如何更改 angularjs $http.jsonp 的标头 [英] how to change the headers for angularjs $http.jsonp
本文介绍了如何更改 angularjs $http.jsonp 的标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我阅读了文档.
但我想我一定是误会了.
but I think I must have misunderstood it.
$http.defaults.headers.jsonp = { 'Accept' : 'application/json'};
$http.jsonp(url).success(function(data, status, headers, config) {
我也试过
$httpProvider.defaults.headers.jsonp = { 'Accept' : 'application/json'};
$http.jsonp(url).success(function(data, status, headers, config) {
我想将 Accept
更改为 application/json
都不起作用.
推荐答案
在使用 JSONP 时无法控制浏览器发送的标头.JSONP 是一个聪明的技巧(或黑客,取决于你如何看待它......),它包括插入一个指向服务器端点的 标记.最终由浏览器决定在通过
<script>
标记请求脚本时发送哪些标头,您无法影响它.
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 请求的 HTTP 标头
这篇关于如何更改 angularjs $http.jsonp 的标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文