简体   繁体   中英

Angular JS http Request to .NET Server

Im trying to make a post request to a .NET server using Angular JS

I am able to get a response but the server is not seeing my request data.

Client:

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

var data = {name:"bill", email:"bill@email.com", phone:"1234567890" };

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

    console.log(res.data);

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

Server:

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

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

Im not super familiar with .NET . Is Request.Form the basically like $_POST in php?

How can I pass some variable over to the server using $http ?

Try sending the data as string by using JSON.stringify(data) . And additionally you can explicitly specify content type header 'Content-Type': 'application/json'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM