POST throws HttpRequestMessage does not contain a definition for Form

前端 未结 1 1575
灰色年华
灰色年华 2021-01-19 19:57

I am trying to get POST data in C# and everything I have read says to use

Request.Form[\"parameterNameHere\"]

I am trying that, but I get

相关标签:
1条回答
  • 2021-01-19 20:08

    You should pass your object in the request body and retrieve values from the body:

    public HttpResponseMessage Post([FromBody] SomeModel model)
    {
        var value = model.SomeValue;
        ...
    

    Or if all you need is the string:

    public HttpResponseMessage Post([FromBody] string value)
    {
        HttpResponseMessage response = new HttpResponseMessage();
        response.Content = new StringContent("Your message to me was: " + value);
        return response;
    }
    
    0 讨论(0)
提交回复
热议问题