[英]AngularJS $http.post how to set the json data into request body
I am trying to send the post request with json data to server. 我正在尝试将带有json数据的发布请求发送到服务器。 But seems angularJS $http.post method does not set the data into body.
但是似乎angularJS $ http.post方法没有将数据设置为主体。 How can I make it set the data into body?
如何使其将数据设置为正文?
The remote server is implemented use asp.net webapi and will read the data from body. 远程服务器是使用asp.net webapi实现的,它将从正文中读取数据。 so I need to set the json data into request body.
所以我需要将json数据设置为请求正文。
How can I implement this please? 请问如何实施? Thanks.
谢谢。
If the request send to same site, then it works. 如果请求发送到同一站点,则它可以工作。 But if I send the request to CROS server, it does not work.
但是,如果我将请求发送到CROS服务器,它将无法正常工作。
In the remote backend server, I already updated the webconfig to make it support CROS call, but it still does not work. 在远程后端服务器中,我已经更新了webconfig以使其支持CROS调用,但仍然无法正常工作。
$http.post(resourceUri, requestData)
.success(function (response) {
})
.error(function (data, status, header, config) {
});
You could build the request like this: 您可以这样构建请求:
var req = {
method: 'POST',
url: 'http://example.com',
headers: {
'Content-Type': "application/json"
},
data: { test: 'test' }
}
$http(req).success(function(){...}).error(function(){...});
YOu can do it as follows 1. make a controller 2. make a add data to the call 您可以按以下步骤进行操作:1.制作控制器2.在通话中添加数据
syntax for the post call is as follows 调用的语法如下
$http.post(url, data, [config])
app.controller('controller', function ($scope, $http, $routeParams) {
$http.post('url',data.call1($routeParams.id))
.success(function (response) {
$scope.response = response;
})
.error(function (data, status, headers, config) {
});
});
var data = {
call1:
function (value) {
return {'key': value, 'key': 'some text'};
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.