使用angularjs发送标头请求

时间:2017-01-12 10:34:27

标签: angularjs

我必须从angularjs调用一个Web服务。调用此Web服务操作时,HTTP标头必须包含OT-Authentication,如下所示:

GET 'url'

Accept-Encoding: gzip,deflate

**OT-Authentication: 'auth_token'**

Host: 'host'

Connection: Keep-Alive

User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

我试过这个angularjs代码:

$scope.products=[];

$http.get(url,{headers:{"OT-Authentication":auth_token}},{cache:true}).success(function(response){
$scope.products=response.data;});

这会生成HTTP OPTIONS请求而不是GET请求,请求标头如下所示:

Host: 'host'

User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Language: en-US,en;q=0.5

Accept-Encoding: gzip, deflate

**Access-Control-Request-Method: GET**

**Access-Control-Request-Headers: ot-authentication**

Origin: 'url'

如何使用必要的请求标头生成GET请求?

0 个答案:

没有答案