简体   繁体   English

响应对象为空以获取REST API的请求

[英]Response Object coming null for get request for rest api

I am trying to implement nexmoverify REST API for OTP implementation but response object comig null.I checked in Postman and able to get stringify object from of response object. 我试图为OTP实现实现nexmoverify REST API,但响应对象为comig null。我签入Postman并能够从响应对象获取字符串化对象。

var app = angular.module('angularjs-starter', []);
app.config(['$httpProvider', function($httpProvider) {
   $httpProvider.defaults.useXDomain = true;
   delete $httpProvider.defaults.headers.common['X-Requested-With'];
}
]);

app.controller('MainCtrl', function($scope, $http) {


   $scope.addNewChoice = function () {
      console.log('aaaa');
      $scope.res=$http.get("https://api.nexmo.com/verify/json?api_key=56a9b1af&api_secret=XXXXXX&number=919650298011&brand=stayuncle").
         success(function (response) {
            $scope.res = response.data;


         }).
      error(function (response){
            console.log(response);

            $scope.res = response.data;


         });


   };

Code Flow: code flow coming to error() section and then printing null in web console. 代码流: code flow coming to error() section and then printing null in web console.

Error : 错误:

Response object coming null as well as getting this error in web console 

XMLHttpRequest cannot load https://api.nexmo.com/verify/json?api_key=56X9b1af&api_secret=d3XXXX&number=91XX50298011&brand=stayuncle. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.

Can someone help me to solve this problem. 有人可以帮我解决这个问题。

The error tells you the problem. 该错误告诉您问题所在。

No 'Access-Control-Allow-Origin' header is present on the requested resource. 所请求的资源上没有“ Access-Control-Allow-Origin”标头。 Origin ' http://localhost:8080 ' is therefore not allowed access. 因此,不允许访问源' http:// localhost:8080 '。

The REST API server is not configured for CORS, therefore, you are not allowed to access that URL from any origin other than the https://api.nexmo.com/ domain. 未为CORS配置REST API服务器,因此,除https://api.nexmo.com/域之外,您不能从任何其他来源访问该URL。 However, aren't you supposed to be using JSONP? 但是,您不应该使用JSONP吗?

Reference on CORS 关于CORS的参考

Reference on JSONP JSONP参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM