About modification in ASP.NET WEBAPI the POST request FromBody of type string parameter server gets a simple solution to a null value is less than the value FromBody

In fact, the solution is simple, it is time POST request parameters from the entity, content-type: application / x-www-form-urlencoded case, in accordance with the default key-value pairs to resolve, such as paramname = paramvalue of form, but there is a hidden requirement is frombody parameters can only be one, if more parameters are modified to frombody, the compiler will complain when, that is, means that, as long as frombody modified parameters, whose name is not important, the body part then http request directly from the name of the parameter is ignored, began to write parameter = content from, it can be directly read as string type. If you do not understand, look at the following screenshot demonstration:

 

The figure is a simulated http request, the server-side code in FIG., The figure is performed immediately after the completion of value inserted into the database,

Where there are concerns at 3,

1, the server side code can be seen that the need to pass two parameters, the parameters are of the type string, a difference is extracted from the url, extracted from the body in another, it has been written in a url parameters, no back & add to keep up with the other parameters,

2, the data content is actually a body to fill in the content, form default encoding is utf-8, body uploaded content, and url can not be in the same key-value pairs, key = value form does not endorse, on the contrary, = start from, all of the types of parameters as a sting frombody be transmitted later, if not start = number, the message on the server will be null null,

3, data content, i.e. the content length parameter body, must have, in http1.1 above, if the POST, and when the body of non-null, must be content-length header, and, if kanji characters exist, then re utf-8 coding mode, the length should be encoded using the character length rather than length before coding, i.e. the length of the byte array, if the person can not believe handwritten again to confirm.

Of course, the case for online frombody argument is null, there are a lot of people have suggested themselves to do a reading class to handle parameter, or string type to object to receive, and then caught into such a form to receive the json, but the content-type have to do is change the text / json, etc., I think it is way more complicated than this, absolutely not as good as this way of simple and convenient.

The way to make a broadcast of it: https: //shop122721410.taobao.com/ is my Taobao shop, if you have any questions, you can find me at any time, usually online.

Guess you like

Origin www.cnblogs.com/zhaimaojun/p/FromBody.html