简体   繁体   English

如何在angular js(版本1.4.8)中将授权标头发送到http请求

[英]How to send authorization header to a http request in angular js (version 1.4.8)

snapshot on server side 服务器端快照

The above screenshot is while I debug the web service which is hit during my javascript call. 上面的屏幕截图是我调试在javascript调用中被击中的Web服务时。 I want to set the authorization header of the http request which is returning null. 我想设置返回null的http请求的授权标头。 Can you please suggest me for this 你可以为此建议我吗

 var config = {
      method: 'POST',
      url: 'https://somesite.com/',
      headers: {
            // key value pair of headers
            'Authorization': 'Your auth key'
      },
      data: body of request
  };
 $http(config)
         .success(function(){})
         .error(function(){})

You can add this in your http request: 您可以将其添加到您的http请求中:

headers: {'Authorization': 'Basic key'}

Examples 例子

GET request: GET请求:

$http.get('url', { //same for post also
    headers: {'Authorization': 'Basic key'}
});

Post Request: 张贴要求:

$http.post("url", requestData, {
    headers: { 'Authorization': 'Basic yourkey'}
}).success(function(responseData) {
    //do stuff with response
});

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

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