传递数据的阵列从角$ HTTP POST [英] Pass array of data from Angular $http POST
问题描述
我需要从我的角度应用传递对象数组与南希框架.NET Web服务。
I need to pass an array of object from my Angular application to a .Net web service with Nancy framework.
我试过这样:
function TestCtrl($scope, $http){
$scope.postTest = function(){
var data = [obj1, obj2, obj3];
$http({
url: 'myURL',
method: "POST",
data: data,
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}
}).success(function(data){
alert("done");
});
}
}
但服务器发送500内部服务器错误。
我不知道为什么它不工作。我不是一个专家网络服务专家,但我认为这是一个序列化的问题。
But server send 500 Internal server error.
I don't know why it doesn't work. I'm not an expert web service expert but I think it's a serialization problem.
有人能帮助我吗?
推荐答案
据<一个href=\"http://stackoverflow.com/questions/11442632/how-can-i-make-angular-js-post-data-as-form-data-instead-of-a-request-payload\">this帖子,你是对的,这是关于序列化。 角没有自动序列化你的数据的,你需要在发送前解析数据:
According to this post, you're right, this is about serialization. Angular doesn't automatic serialize the data for you, you need to parse the data before sending it:
...
$http({
url: 'myURL',
method: "POST",
data: $.param(data),
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}
})...
如果你不使用jQuery,你需要推出自己的 $。分析
。有一个<一href=\"http://stackoverflow.com/questions/1714786/querystring-encoding-of-a-javascript-object\">snippet这里或者你可以适应jQuery的实施。
If you don't use jQuery, you'll need to roll your own $.parse
. There is a snippet here or you could adapt jQuery implementation.
这篇关于传递数据的阵列从角$ HTTP POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!