gpt4 book ai didi

javascript - Angular $http POST 将空对象作为正文发送

转载 作者:可可西里 更新时间:2023-11-01 16:07:29 28 4
gpt4 key购买 nike

我有一些非常普通的代码,但似乎无法找出问题所在。在服务器端,我在发送下面的 POST 时在请求正文中得到一个空对象。我在服务器端使用 express。当我使用 Postman 时,我的服务器端工作正常,所以据我所知服务器端不是问题。从我能找到的所有内容来看,下面的代码应该可以正常工作:

$http({
method: 'POST',
url: 'http://localhost:5000/authRequest',
headers : { 'Content-Type' : 'application/json' },
body: {
'test' : 'test'
}
});

有什么想法吗?

最佳答案

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

post请求中没有'body'这样的参数。你应该使用“数据”:

$http({
method: 'POST',
url: 'http://localhost:5000/authRequest',
headers : { 'Content-Type' : 'application/json' },
data: {'test' : 'test'}
}).then(function(response){
// your logic for viewing
});

关于javascript - Angular $http POST 将空对象作为正文发送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42764253/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com