简体   繁体   English

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

[英]how to change the headers for angularjs $http.jsonp

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. 都没有工作。

There is no way to control headers sent by a browser while using JSONP. 使用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. JSONP是一个聪明的技巧(或黑客,取决于你如何看待......),包括插入指向服务器端点的<script>标记。 Ultimately it is a browser who will decide which headers to sent while requesting scripts via <script> tag and you can't influence it. 最终,它是一个浏览器,它将决定在通过<script>标记请求脚本时发送哪些标头,而您无法影响它。

More info here: Modify HTTP Headers for a JSONP request 更多信息: 修改JSONP请求的HTTP标头

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

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