I have been trying to post JSON array to the server using angularjs. but its not reading the array part.I am able to send the non array part which are username,password and status with the following code
$http({
method: 'POST',
url: 'http://localhost:57302/api/Messages',
data: {
"Username": "SampleUsername",
"Password": "SamplePassword",
"Messages": [{
"From": "Harsh",
"to": "Rahul",
"Body": "Hi there",
}, {
"From": "Harsh",
"to": "Rahul",
"Body": "How are you",
}, {
"From": "Rahul",
"to": "Harsh",
"Body": "I am Good",
}],
"Status": "SampleStatus",
},
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
transformRequest: function(obj) {
var str = [];
for (var p in obj)
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
return str.join("&");
}
})
What changes are required in order to send the array part as well?