加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

AngularJs DELETE与数据集错误的内容类型头

发布时间:2020-12-17 07:37:06 所属栏目:安全 来源:网络整理
导读:我正在使用一个$http DELETE请求与一个有效载荷,但内容类型是错误的.我有一个数据对象,但是内容类型被设置为text / plain而不是application / json.从下面的代码和下面的网络请求可以看出,实际上是一个带有值的数据对象.有没有办法解决这个问题?非常感谢!
我正在使用一个$http DELETE请求与一个有效载荷,但内容类型是错误的.我有一个数据对象,但是内容类型被设置为text / plain而不是application / json.从下面的代码和下面的网络请求可以看出,实际上是一个带有值的数据对象.有没有办法解决这个问题?非常感谢!

码:

$http({  
        method: "DELETE",url: ".../v2/places/" + place.id + "/locations/remove",data: location,headers: { Authorization: "Bearer " + rootServices.getToken() }  
    })

chrome网络请求摘要:

Remote Address:54.83.54.37:443
URL:../v2/places/53b43e03e4b00cb25bcb16af/locations/remove
Request Method:DELETE
Status Code:500 Internal Server Error Request
Accept:application/json,text/plain,*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Authorization:Bearer …..
Connection:keep-alive
Content-Length:66
Content-Type:text/plain;charset=UTF-8
Host:sandbox….net
Origin:127.0.0.1:9000
Referer:127.0.0.1:9000/session
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36
(KHTML,like Gecko) Chrome/35.0.1916.153 Safari/537.36 Request
Payload: {room:Kitchen,appliance:Refrigerator,floor:Main
Floor}

您可以将标题中的内容类型与授权标题一起设置
$http({  
        method: "DELETE",headers: {'Content-Type': 'application/json',Authorization: "Bearer " + rootServices.getToken() }  
    })

或者您可以将其设置为广泛的:

module.config(function($httpProvider) {
  //$http.defaults.headers.common.Authorization = 'Basic YmVlcDpib29w'
  $httpProvider.defaults.headers.delete = { 'Content-Type' : 'application/json' };
});

文档状态:

Setting HTTP Headers The $http service will automatically add certain
HTTP headers to all requests. These defaults can be fully configured
by accessing the $httpProvider.defaults.headers configuration object,
which currently contains this default configuration:

$httpProvider.defaults.headers.common (headers that are common for all
requests): Accept: application/json,* / *
$httpProvider.defaults.headers.post: (header defaults for POST
requests) Content-Type: application/json
$httpProvider.defaults.headers.put (header defaults for PUT requests)
Content-Type: application/json To add or overwrite these defaults,
simply add or remove a property from these configuration objects. To
add headers for an HTTP method other than POST or PUT,simply add a
new object with the lowercased HTTP method name as the key,e.g.
`$httpProvider.defaults.headers.get = { ‘My-Header’ : ‘value’ }.

The defaults can also be set at runtime via the $http.defaults object
in the same fashion. For example:

https://docs.angularjs.org/api/ng/service/$http

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读