angularjs – 角度,内容类型不与$http一起发送

前端之家收集整理的这篇文章主要介绍了angularjs – 角度,内容类型不与$http一起发送前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Angular没有添加正确的内容类型选项,我试过以下命令:
$http({
    url: "http://localhost:8080/example/teste",dataType: "json",method: "POST",headers: {
        "Content-Type": "application/json"
    }
}).success(function(response){
    $scope.response = response;
}).error(function(error){
    $scope.error = error;
});
@H_301_3@上面的代码生成以下http请求:

POST http://localhost:8080/example/teste HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Content-Length: 0
Cache-Control: no-cache
Pragma: no-cache
Origin: http://localhost:8080
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.31 (KHTML,like Gecko) Chrome/26.0.1410.64 Safari/537.31
Content-Type: application/xml
Accept: application/json,text/plain,*/*
X-Requested-With: XMLHttpRequest
Referer: http://localhost:8080/example/index
Accept-Encoding: gzip,deflate,sdch
Accept-Language: pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: JSESSIONID=C404CE2DA653136971DD1A3C3EB3725B
@H_301_3@正如你所看到的,内容类型是“application / xml”,而不是“application / json”。我在这里缺少什么?

您需要包含请求的正文。否则角度删除内容类型标题。 @H_301_3@将数据:“”添加到$ http的参数。

猜你在找的Angularjs相关文章