I am trying to post key-value pair data from angular application to a asp.net page however I am not able to receive the result at the asp.net page.
Example Data
{fullName: "Vikas Bansal", userId: "1001387693259813", userimageurl: "http://graph.facebook.com/1001387693259813/picture?width=250&height=250"}
Angular Code
var postData = {
fullName: $scope.name,
userId: $scope.userId,
userimageurl: $scope.userImage
};
var postUrl = 'http://localhost:41115/Index.aspx';
$http({
url: postUrl,
method: "POST",
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data: postData
}).then(function (responce) {
console.log(responce);
}, function (responce) {
console.log(responce);
});
Asp.net Page Code
protected void Page_Load(object sender, EventArgs e)
{
var userId = Request.Form["userId"]; /// getting null
var fullName = Request.Form["fullName"]; /// getting null
var img = Request.Form["userimageurl"]; /// getting null
}
In asp.net page all variables are null.
EDIT
By changing content type to 'Content-Type': 'application/json; charset=utf-8' in angularJs post request
and by using var strJSON = (new StreamReader(Request.InputStream).ReadToEnd()); I am able get the posted json
but I am still wondering if there is a way to get key-value pairs directly?
like this var userId = Request.Form["userId"];

Content-Typetoapplication/json; charset=utf-8.