如何更改标头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) {

我想改变接受应用程序/ JSON

无论是工作。

有没有办法控制,同时使用JSONP通过浏览器发送头。 JSONP是一个聪明的把戏(或黑客攻击,这取决于你怎么看......)那由插入&LT的;脚本> 标记指向的服务器端点。最终,它是一个浏览器谁将会同时通过请求脚本,头决定发送<脚本方式> 标签,你不能影响它

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.

此处了解详情:修改的HTTP标头JSONP申请