How to get POST data in WebAPI?

前端 未结 8 1355
天涯浪人
天涯浪人 2020-11-29 21:32

I\'m sending a request to server in the following form:

http://localhost:12345/api/controller/par1/par2

The request is correctly resolved t

8条回答
  •  甜味超标
    2020-11-29 21:58

    Is there a way to handle form post data in a Web Api controller?

    The normal approach in ASP.NET Web API is to represent the form as a model so the media type formatter deserializes it. Alternative is to define the actions's parameter as NameValueCollection:

    public void Post(NameValueCollection formData)
    {
      var value = formData["key"];
    }
    

提交回复
热议问题