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>
标记.最终,浏览器将决定在通过 <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 的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何更改 angularjs $http.jsonp 的标题


基础教程推荐
- Bootstrap 模态出现在背景下 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01