2017-09-06 39 views
0

我试着做一个post请求采用了棱角分明JS角JS HTTP请求到.NET服务器

.NET服务器我能够得到回应,但服务器没有看到我的请求数据。

客户:

var header = {"Content-Type":"multipart/form-data"}; 

var data = {name:"bill", email:"[email protected]", phone:"1234567890" }; 

$http.post("//dot.net/resource", data, header).then(function(res){ 

    console.log(res.data); 

},function(err){ console.log(err); }); 

服务器:

if(HttpContext.Current.Request.HttpMethod.ToString().ToLower() == "post") { 

    Response.Write("hello request");  // I see this in the response 
    Response.Write(Request.Form["name"]); // nothing : (
} 

我不是超级熟悉的.NET。是Request.Form基本上像$_POST在PHP?

如何使用$http将某些变量传递给服务器?

回答

1

尝试使用JSON.stringify(data)作为字符串发送数据。此外,您可以明确指定内容类型标头 'Content-Type': 'application/json'