Application/x-www-form-urlencoded interface Response message Chinese garbled

Source: Internet
Author: User

1. How to handle garbled characters

In the case of an interface test, when using the HttpClient POST request, for Content-type:application/json, you only need to specify the appropriate encoding for the header information and the POST request when writing the test script. General interface response results do not appear in Chinese garbled situation, but application/x-www-form-urlencoded this way you even for the header information and the POST request to specify the corresponding code, the interface response results will still garbled, then how to deal with it? Simply set the interface return message to UTF-8.

Add header information: ("Content-type", "application/x-www-form-urlencoded; Charset=utf-8");

Interface Response message: Response.getbody ()

string result = new String (Response.getbody (). GetBytes ("Iso-8859-1"), "UTF-8");

Before processing:

After processing:

2. Commonly used data formats for sending requests

1). application/x-www-form-urlencoded

In the syntax of the form element, Enctype indicates that the format for submitting data uses the Enctype property to specify the type of encoding the browser will use when sending data back to the server. Below is the description: application/x-www-form-urlencoded: The form data is encoded as a name/value pair. This is the standard encoding format. Multipart/form-data: The form data is encoded as a message, and each control on the page corresponds to a part of the message. Text/plain: Form data is encoded in plain text with no control or formatting characters.
The Enctype property of a form is encoded in two common ways: application/x-www-form-urlencoded and Multipart/form-data, which are application/by default. X-www-form-urlencoded. When action is get, the browser uses x-www-form-urlencoded encoding to convert the form data into a string (Name1=value1&name2=value2 ... ), and then append the string to the URL, using the. Split, to load the new URL. When the action is post, the browser encapsulates the form data into the HTTP body and then sends it to the server. If you don't have a type=file control, you can use the default application/x-www-form-urlencoded. But if you have type=file, you will need to use Multipart/form-data. The browser splits the entire form into units of controls and adds Content-disposition (form-data or file) to each section, Content-type (default = Text/plain), name (control name), and so on. and add the separator (boundary).

2) Application/json

This content-type as a response head everyone must be no stranger. In fact, more and more people now use it as a request header to tell the server that the message body is a serialized JSON string

Application/x-www-form-urlencoded interface Response message Chinese garbled

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.