I have a very simple .NET Web API hosted in Azure, with two very simple methods:
[EnableCors(origins: "http://simpleapiearl.azurewebsites.net", headers: "*", methods: "*")]
public class EnvelopesController : ApiController {
// GET: api/Envelopes
public IEnumerable<string> Get() {
return new string[] { "value1", "value2" };
}
// POST: api/Envelopes
public string Post([FromBody]Envelope env) {
return "rval: " + env + " (and my addition to env)";
}
}
I have created a simple plunk to call these methods. In my AngularJS code, I'm making two very simple $http calls. The GET works fine. The POST, however, always returns a "400 (Bad Request)", followed shortly in my WebStorm console by "XMLHttpRequestion cannot load ... Invalid HTTP status code 400".
Any and all suggestions appreciated!
EDIT!!
Hello, and thanks for the very fast responses. I just realized I forgot to add some very relevant detail.
The parameter to my POST method is what I call an Envelope object, which contains two properties: listingId (int)
, and Description (string)
. When I add the urlencoded Content-Type header, and pass '{"listingId":1234, "Description":"some description"}'
as my POST data, the env parameter in my POST method on the server is NULL (that is, it seems unable to parse the JSON I'm providing). Sorry this was omitted from original post.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…