简体   繁体   English

带有基本身份验证的$ http.get()在IONIC的AngularJS中的OPTIONS调用中失败

[英]$http.get() with Basic Auth is failing at OPTIONS call in AngularJS, IONIC

I am making a call from ionic app with following code:- 我正在使用以下代码从离子应用程序拨打电话:-

 var req={ method: "GET", url: "<Some URL>", headers:{ "Authorization": "Basic YjEyMDMwOmJjb25lQDEyMw==" } } $http(req).then(function success(){ alert("Yesss"); },function failure(a,b,c){ alert("nahhh"); }) 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 

Below image shows failure in OPTIONS call. 下图显示了OPTIONS调用中的失败。

Failing call in console 控制台呼叫失败

Whereas same call works fine from SAPUI5 which takes care of CORS internally with oModel.Read() operation. 而从SAPUI5进行的调用也可以正常工作,后者通过oModel.Read()操作在内部处理CORS。 Below is the successful call screenshot:- 以下是成功的电话屏幕截图:-

Passing call in console 在控制台中转接电话

What am i doing wrong? 我究竟做错了什么? or is it even possible to make CORS based call from AngularJS app? 或者甚至可以从AngularJS应用程序进行基于CORS的调用?

edit1: 编辑1:

I just noticed, if i give header- Authorization, rest of the headers are ignored, and accept goes with text/plain... etc But if authorization header is not there, it takes Accept and other params, but since my service is Basic auth based, it would need this header, now how do i crack this? 我只是注意到,如果我给Header- Authorization,其余的头将被忽略,并且accept与text / plain一起使用...等等。但是,如果授权头不存在,它将接受Accept和其他参数,但是由于我的服务是Basic基于身份验证,将需要此标头,现在我该如何破解呢?

edit2: I tried same thing in $.get ajax call, and noticed, if i pass "Authorization" header or any other random header like "doijwoid" no other headers are shown in request header calls, but when i omit this header other headers like "Accept" works as written in code. edit2:我在$ .get ajax调用中尝试过同样的事情,并注意到,如果我传递“ Authorization”标头或“ doijwoid”之类的任何其他随机标头,则请求标头调用中不会显示其他标头,但是当我省略此标头时,会显示其他标头就像“接受”一样,都是用代码编写的。

 $.get({url:"<SRV URL>",headers:{"Accept":"application/json"}}, function(data, status){ alert("Data: " + data + "\\nStatus: " + status); }); 

[Ajax call without authorization header][3] [无授权头的Ajax调用] [3]

[Call with Authorization header and Accept as well, but accept header not taken][4] [使用授权标头调用,也接受,但不接受标头] [4]

您是否已在服务器上签入CORS?

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

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