web-api POST body object always null

前端 未结 26 3046
余生分开走
余生分开走 2020-11-27 15:03

I\'m still learning web API, so pardon me if my question sounds stupid.

I have this in my StudentController:

public HttpResponseMessage          


        
26条回答
  •  悲哀的现实
    2020-11-27 15:36

    If this is because Web API 2 ran into a deserialization problem due to mismatched data types, it's possible to find out where it failed by inspecting the content stream. It will read up until it hits an error, so if you read the content as a string, you should have the back half of the data you posted:

    string json = await Request.Content.ReadAsStringAsync();
    

    Fix that parameter, and it should make it further next time (or succeed if you're lucky!)...

提交回复
热议问题