http POST request four common way to submit data

Common http request classified into four content-type: application / json, x-www-form-urlencoded, multipart / form-data, text / plain.

enctype attribute specifies before being sent to the server how to encode the form data. By default, the form data is encoded as "application / x-www-form-urlencoded". That is, before being sent to the server, all characters are encoded (converted to spaces "+" plus, special symbols into ASCII HEX value).

enctye available options are as follows:

1 Overview

The HTTP request method specified in HTTP / 1.1 protocol has OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT these types. Wherein POST typically used to submit the data to the server, this paper discusses ways to POST submit data.

HTTP protocol is based on ASCII code transmission. He is based on the standardized application layer TCP / IP protocol, the HTTP request is divided into a predetermined three parts:

. State line

. request header headers

. entity-body message body

It resembles the following:

HTTP POST data submitted agreement must be placed in the message body (entity-body) but does not have any predetermined data encoding used. In fact, the developer can decide the format of the message body, HTTP requests sent last as long as meet the above format can be.

Singular, data sent, but also successfully resolved the server makes sense. General service side language such as php, python, as well as their framework, are built to automatically resolve common data format function. Server typically be learned message body of the request in accordance with the request header (headers) in a Content-Type field is the manner in which the encoding, and then parses the subject. So submit POST data contains the Content-Type and message body encoding of two parts, the following officially began their presentation.

2 Introduction

1)application/x-www-form-urlencoded

The default HTTP submission of data. Native browser <form> form, if not set enctype attribute, then the final data will be submitted to application / x-www-form-urlencoded manner. Request is similar to the following:
By Ethereal result we get the following conclusions: 

. Content-Type is designated as a file application / X-WWW-form-urlencoded 
. Submitted data encoded according val1 manner key1 = & key2 = val2 of, key, and have carried out a URL val transcoding. Most server-side languages have very good support for this approach.

2)multipart/form-data

A common way of POST data submitted. When we use the form to upload files, you must set the enctype multipart / form-data.

3)application/json

application / json as the request header is used to tell the server message body is serialized JSON string. Convenient data submitted complex structure, particularly suitable RESTFul interface. The final request is similar to the following: 
major capture tool comes as Chrome Developer Tools, Firebug, Fiddler, will demonstrate JSON data in a tree structure, very friendly. The final request is transmitted:

4)text/xml

XML-RPC (XML Remote Procdure Call). It is using HTTP as the transport protocol, XML as the encoding of the remote calling convention. A typical XML-RPC request is such that:
XML-RPC protocol is simple, functional enough to achieve a variety of languages ​​are. Its use is very broad, such as search engine ping services.

 

Guess you like

Origin www.cnblogs.com/relustarry/p/12525893.html