jmeter Processing Content-Type http request type and parameter passing mode

  introduction

  We do interface testing time often ignore the data type content-type format and parameters Parameters and Body Data differences and use.

 

For the first time students contactless interface for himself when sending a http request, there will always encounter various problems, such as will pass parameter does not exist ah.

 

Similar problems arise such problems should be the first rule of the content-type is correct, then what is the content-type it?

 

In the process of client and server interaction via http request, you gotta tell the server what format you pass the type of data it (easy to parse the data server)

 

content-type is to tell the client server data is similar to what is, and is passed to the server through the first header, data type, if passed by the client is wrong, the server is not resolved, can not be verified.

 

So before a test request, we must find out what is http data format type.

 

 

 

       Post here is mainly about a method embodiment of the Http request protocol, the Get method thereof relative difference is:

  GET: requests data from the specified resource.

  POST: submission of data to be processed to the specified resource

The most intuitive performance is:

The GET parameter contained in the URL, POST request submitted to the server overall transmission parameters Request Body. To distinguish between the two treatment methods so when the interface test.

The following describes three types of data POST request in the content-type:

  1. content-type:application/x-www-form-urlencoded
  2. content-type:application/json
  3. content-type:multipart/form-data

  

  The first type

1、【content-type:application/x-www-form-urlencoded】

如果不指定content-type,默认使用此格式。

参数格式:key1=value1&key2=value2。

假设使用Parameters参数格式,而不设置content-type,默认使用此格式。

反之如果设置content-type:application/json,就会报错。

 Figure:

  

 

 

 

Knock on the blackboard: So when using the Parameters parameter format, either do not set the content-type type, or set the content-type: application / x- www-form-urlencoded, not by content-type: application / json type to the request, otherwise an error! ! !

 

Using the content-type: application / time x-www-form-urlencoded, there is a body data in the packet request to go inside.

Figure:

 

 

 

 

 

  The second type

2、【content-type:application/json】

以Json格式编码数据体,方便传输结构化数据(相比键值对),广泛用于 ajax 请求。

参数为json格式 :
{

 "key1":"value1",

 "key2":"value2"

}

 

 

Figure:

 

 

 

 

 

 Knock blackboard: use Body Data, Content-Type transmissibility application / x-www-from- urlencoded or application / json, is the difference between the two different data formats. But if the interface defined data types Content-Type is application / json, it must use the application / json to pass parameters, otherwise an error! ! !

 

 

  The third type

3、【content-type:multipart/form-data】

需要在表单中进行文件上传时,就需要使用该格式,这种格式一般很的少。

  Examples of subsequent supplementary ~

 

 

  to sum up

In summary, we do the first two daily use interface test Basically, these two comes down to is out three different scenarios:

  • application/x-www-form-urlencoded + Parameters

  • application/x-www-form-urlencoded + Body Data

  • application/json + Body Data

  • get request directly with "&" in the splice parameter url

 

Parameters and Body Data Jmeter the two types of parameters of ways, in general, the Get Request Parameters used, with Post request Body Data.

The exact method is for the Post are: ordinary post requests and upload interfaces, select Parameters.

Json and Xml point data format of the request interfaces, select Body.

It is explained in detail, according to the format of the post request data, two cases: map format, JSON format.

What type of data, but also what type of interface definitions, as defined by the interface is application / x-www-form-urlencoded this type, content-type have to use this, and vice versa. Otherwise error!

 

 

 

References. 1 : https://testerhome.com/topics/12687

Reference 2 : https://www.cnblogs.com/insane-Mr-Li/p/10686797.html

 

 

 

 

 

 

 

 

 

 

 

 

 
Published 82 original articles · won praise 43 · views 180 000 +

Guess you like

Origin blog.csdn.net/liudinglong1989/article/details/104549521