When we have the data to the server post, form or JSON

Web front end development, post to send requests to the server operating commonplace. When sending a post request, data transfer, if necessary, the data is contained in the message body.

# HTTP request
<Method> <-Request the URL> <Version>
<headers>

<Entity-body> # message body
way to transfer data in two ways: the form and json. When using the form, the data type is plain text data, or a file (large binary data or data containing non-ASCII characters). And means json JSON string serialized.

For form mode, encoding the message body in three ways:

application / x-www-form- urlencoded & separated using
text / plain used \ n \ r separated
multipart / form-data using a similar boundary = - xxx spaced
x-www-form-urlencoded this way can only transmit common text data, then in order to provide file upload function, proposed form-data mode, you can achieve data and text files hybrid transmission, the so-called multipart.

For json, encoding of the message body is: application / json

Encoding the message body designated by the Content-Type field. Sometimes the distal Content-Type message transfers might request fails, because it is possible to design the rear end of the interface when the type of data transfer is set in advance, it also using the corresponding decoding method. If the front end without the knowledge of this, using the wrong encoding format, it will cause the request to fail. This time to remove the Content-Type set, the problem may be solved.

Author: gaoshu883
link: https: //www.jianshu.com/p/f1fa0b275290
Source: Jane books
are copyrighted by the author. Commercial reprint please contact the author authorized, non-commercial reprint please indicate the source.

Guess you like

Origin www.cnblogs.com/cn-oldboy/p/12635895.html