如何更改angularjs $ http.jsonp的标头

时间:2021-09-06 12:11:32

I read the document.

我读了这份文件。

but I think I must have misunderstood it.

但我想我一定是误解了它。

$http.defaults.headers.jsonp = { 'Accept' : 'application/json'};
$http.jsonp(url).success(function(data, status, headers, config) {

I also have tried

我也试过了

$httpProvider.defaults.headers.jsonp = { 'Accept' : 'application/json'};
$http.jsonp(url).success(function(data, status, headers, config) {

I wanted to change the Accept to application/json

我想将Accept更改为application / json

Neither work.

1 个解决方案

#1


6  

There is no way to control headers sent by a browser while using JSONP. JSONP is a smart trick (or a hack, depending on how you see it...) that consist of inserting a <script> tag pointing to a server endpoint. Ultimately it is a browser who will decide which headers to sent while requesting scripts via <script> tag and you can't influence it.

使用JSONP时无法控制浏览器发送的标头。 JSONP是一个聪明的技巧(或黑客,取决于你如何看待......),包括插入指向服务器端点的

More info here: Modify HTTP Headers for a JSONP request

更多信息:修改JSONP请求的HTTP标头

#1


6  

There is no way to control headers sent by a browser while using JSONP. JSONP is a smart trick (or a hack, depending on how you see it...) that consist of inserting a <script> tag pointing to a server endpoint. Ultimately it is a browser who will decide which headers to sent while requesting scripts via <script> tag and you can't influence it.

使用JSONP时无法控制浏览器发送的标头。 JSONP是一个聪明的技巧(或黑客,取决于你如何看待......),包括插入指向服务器端点的

More info here: Modify HTTP Headers for a JSONP request

更多信息:修改JSONP请求的HTTP标头