How Do I Set the Content Type Header of an HttpClient Request?

Updated on number 2024-02-17
2 answers
  1. Anonymous users2024-02-06

    The content-type property specifies the HTTP content type of the request and response. If no contenttype is specified, the default response content type is text html, and the default requested content type is application x-www-form-urlencoded. Content-type generally only exists in the post method, because the get method does not contain "body", and its request parameters will be encoded after the url, so it is useless to add content-type to the get method.

    There is a configuration file in nginx, which is mainly a file format that is labeled with content-type.

    Here are a fewCommon content-type

    application x-www-form-urlencoded is a commonly used way to send a single package, a common form submission, or a js package, by default, the data is encoded in key value format and sent to the server.

    multipart form-data is used inSend a post package of the file

    The request header of the multipart form-data must contain a special header information: content-type, and its value must also be specified as multipart form-data, and it must also be specifiedContent splitterThat is, boundary is used to split the content of multiple posts in the request body, such as the file content and the text content naturally need to be separated, otherwise the receiver will not be able to parse and restore the file normally.

    Text XML WeChat uses this data format to send requests. XML-RPC (XML Remote Procedure Call) is a remote call specification that uses HTTP as the transport protocol and XML as the encoding.

    There is no so-called JSON in Application JSON HTTP communication, but it is just to convert String to JSON, that is, Application JSON can understand it as Text Plain, an ordinary string.

    mdn content-type

    Understand the content-type of HTTP

    There are four common ways to submit data in POST.

  2. Anonymous users2024-02-05

    When you use Postman, do you know what the following ones do?

    Here are four commonly used types.

    The form-data in the figure above refers to the multipart form-data

    This is a multi-part friendship multi-** type, which is a common way to roll over the POST data base, and it generates a boundary for splitting different fields. It processes the form's data into a single message, separated by a separator with labels as cells. You can upload key-value pairs or files.

    When the uploaded field is a file, there will be content-type to specify the file type.

    Note that when using a form to upload a file, you must have the enctype of the form equal to this value.

    The x-www-form-urlencoded in the image above refers to the application x-www-form-urlencoded

    Generally used:Form submission, the request parameters will be organized and encoded in the way of key1=val1&key2=val2, and both key and val are transcoded by url and put into the request entity (note that if it is Chinese or special characters such as"/"etc.

    The most commonly used. With this type, the serialized JSON string is submitted, and the server client parses the data in JSON format.

    That is, to pass the XML format, which was more commonly used in the past, and should not be used without touching old projects.

    When content-type is set to application octet-stream, only binary data can be uploaded, which is usually used to upload files, without a key, and can only upload one file at a time.

Related questions
8 answers2024-02-17

0 can cut out a fan in the canvas.

public void getsector(canvas canvas, float radius, double fromdegree, double todegree, op op) >>>More

25 answers2024-02-17

Distinguish what you should do and what you shouldn't do, and use your achievements to repay your parents.

8 answers2024-02-17

Nowadays, many fiber optic modems are equipped with antennas, because telecom suppliers integrated the functions of modems and routers when they designed fiber optic modems, but in order to limit one machine and one number, telecom does not want multiple terminals to access the Internet through one network, so the router function of the fiber optic modem is shielded by creating a new restricted user method in the fiber modem. >>>More

10 answers2024-02-17

I'll teach you a simple way.,No one can open it.,Only if you know the method.,Even if others look at it, they don't know that you added a password.,But he can't open it at all.,He will definitely think that there is a problem with the program.。 >>>More

16 answers2024-02-17

Without Infatuation No. 2, how to prove the heroine's beauty, kindness, decisiveness and other advantages? Without the infatuated male number two, how can the male protagonist have a sense of crisis? How can you be desperate to be with the heroine? >>>More