JMeter foundation - 16. JMeter configuration element [HTTP header manager]

Flourishing 2021-06-10 05:44:33
jmeter foundation jmeter configuration element


JMeter Provides a wealth of configuration elements , The common ones include parametric configuration elements 、HTTP Request defaults 、HTTP Header Manager 、 Counter, etc , These configuration elements are used to set default values and variables , To provide to the later sampler( Sampler ) Use .

Tips : This paper also demonstrates , Use Message body data Options page , To configure Post Requested parameters .

1、 Project description for demonstration

We use JMeter send out Post request , With College management system Project as an example .

The interface documentation is as follows :

 college - newly added
1) Request method :POST
2) Request address :http://127.0.0.1:8000/api/departments/
3) request JOSN message :( need Content-Type=application/json)
4) Call the incoming json The strings are as follows ( We can add more , In between , separate ):
{
"data": [
{
"dep_id":"T01",
"dep_name":"Test college ",
"master_name":"Test-Master",
"slogan":"Here is Slogan"
}
]
}
5) Add a successful return message :
{
"already_exist": {
"results": [],
"count": 0
},
"create_success": {
"results": [
{
"dep_id": "T02",
"dep_name": "Java college ",
"master_name": "Java-Master",
"slogan": "java"
}
],
"count": 1
}
}
6) Add failed id Already exists - Return message :
{
"already_exist": {
"results": [
{
"dep_id": "T01",
"dep_name": "Test college ",
"master_name": "Test-Master",
"slogan": "Here is Slogan"
}
],
"count": 1
},
"create_success": {
"results": [],
"count": 0
}
}
7) Add failed json Format error :
{
"status_code": 400,
"detail": " Request body parameter format error ."
}

2、 Components included in the test plan

Add component operation steps

  1. Create a test plan .
  2. Create thread group : Choose “ test plan ” Right click —> add to —> Threads ( user ) —> Thread group .
  3. Add configuration elements to thread group "HTTP Header Manager " Components : Choose “ Thread group ” Right click —> add to —> The configuration element —> HTTP Header Manager .( Add later )
  4. Add a sampler to the thread group “HTTP request ” Components : Choose “ Thread group ” Right click —> add to —> Sampler —> HTTP request .
  5. Add listeners to the thread group “ Look at the fruit tree ” Components : View results , Choose “ Thread group ” Right click —> add to —> Monitor —> Look at the fruit tree .

The components in the final test plan are as follows :

image

Click the run button , You will be prompted to save the script first , After the script is saved, it will run automatically .

3、HTTP Request interface content

According to the interface document college - newly added Description of the interface , To write JMeter Sampler , As shown in the figure below :

image

4、 View script execution results

college - newly added The interface calls are as follows :

image

We can see in the picture above , Display interface request failed , The returned result says that the interface does not support the media type in the request text/plain.

Let's look at the information in the request header , as follows :

image

Found... In the request header Content-Type by text/plain.

Because we said before , stay JMeter 5.0 In a later version POST When asked , Put the parameters in body data( Message body data ) in , And it's not set Content-Type when , The default will be Content-Type Is set to text/plain.

And in the interface document college - newly added Interface , Write clearly what you need Content-Type The type of application/json.

So at this time, we need to put it in the request header , Redefinition Content-Type The value of the property .

5、 Add request header information (HTTP Header Manager )

stay JMeter Add request header information and Postman There is a difference , You need to add a configuration element to the thread group , be known as HTTP Header Manager HTTP Header Manager). That is to say, it needs to be in HTTP Header Manager In the component , Add the required request header information to the request .

Add configuration component steps : Choose “ Thread group ” Right click —> add to —> The configuration element —> HTTP Header Manager .

As shown in the figure below :

image

HTTP Header Manager The interface is as follows :

image

Interface description

  • name :HTTP Header manager custom name , It's best to see the name and know the meaning .
  • notes : That is to add some remarks , For the HTTP A brief description of the header Manager , For later review .
  • The information in the request header : It can help testers set up JMeter Sent HTTP In request , The information contained in the request header .HTTP The header contains User-AgentReferer Equal attribute . Put it under the thread group as much as possible , Unless for some reason , Testers want different HTTP The request uses a different HTTP Message header .
    1) add to : You can add a request header configuration information .
    2) Add... From the clipboard : Add information from the clipboard ;( Use key+ tabs +value In the form of , You can do more .)
    3) Delete : Select unnecessary request header information , Can be deleted ;
    4) load : Load the configured header file .( I use .txt file , Configure... In the above format , Loading succeeded . You can use the files configured by your company in your work )
    5) Save test plan : Save the test plan .

Pictured above , We add a request header message :Content-Type=application/json.

At this point, the components included in the test plan , As shown in the figure below :

image

Send request again , The request is successful , Here's the picture :

image

Let's take another look , The request header information of the request :

image

You can see... In the request Content-Type The attribute is application/json.

That's all HTTP Header Manager How to use components ,

6、 Priority description

HTTP Header Manager The priority of the component :

  • JMeter Support to add multiple HTTP Header Manager Components , If there are multiple HTTP Header Manager Components , The configuration information is merged .
  • Sampler Next HTTP Header Manager Component's Priority over Thread group Under the HTTP Header Manager Components .
  • If there is a duplicate header name , Priority Sampler Under the HTTP Header Manager Configuration information in components .
  • Under the same scope , No matter how many HTTP Header Manager Components , Only the first one HTTP Header Manager Values in components , Do not merge .

Tips : Each component has a fixed icon , We can tell if we use it more .

7、 Add : Common request header information

  • Accept: Tell the server , Data types supported by clients .
  • Accept-Encoding: Tell the server , Client supported data compression formats .
  • Cache-Control: Cache control , The server controls whether the browser should cache data .
  • Connection: After processing this request , Disconnect or stay connected .
  • Cookie: Through this, the client can bring data to the server .
  • Host: Host name accessed .
  • User-Agent: Tell the server , Client's software environment .
  • Content-Type: Used to indicate resources MIME type .
版权声明
本文为[Flourishing]所创,转载请带上原文链接,感谢
https://qdmana.com/2021/05/20210522100540237g.html

  1. Nginx set up echo agent to realize nginx cluster
  2. Angularjs of $watch a small introduction
  3. Nginx local cache
  4. Vue -- bidirectional data binding
  5. Analyze Ajax, capture the street photos of today's headlines and store the information in mongodb
  6. The differences of CSS units Px, EM, REM, VH, VW, Vmin and Vmax
  7. Development of native module of react native (Android) learning notes
  8. Jsonp - cross domain Ajax
  9. Development of nodejs JavaScript wechat
  10. SSM + bootstrap add, delete, modify, and upload avatars
  11. Vue uses MD5 encryption
  12. Reactnative shares a depressing bug to solve listview
  13. Can not connect to development server
  14. A jQuery plug-in for seamless text scrolling
  15. Nginx in my eyes (4): what makes your nginx service exit so slowly?
  16. Why must parameters of anonymous inner classes be finalhttp://feiyeguohai.iteye.com/blog/1500108
  17. Talk about react
  18. CSS3 note background
  19. IIS, nginx and Apache only allow domain name access configuration
  20. Object oriented programming (OOP) of JavaScript Design Pattern (2)
  21. CSS 3 Learning -- transform 3D Transform rendering
  22. [react] - manually encapsulating a simple version of Redux
  23. Vue: common syntax of ES6
  24. Vue learning notes: introduction to nodejs
  25. Learning notes of JavaScript -- iterative function
  26. Establish communication process and operation mechanism [transfer]
  27. Development of local simulation server CDN (static HTML, CSS, JS)
  28. Access nginx prompt gateway timeout 504, found that always when the call time exceeds 30s prompt 504 error
  29. Web Security Foundation: HTML / CSS | 0x7html5 and W3C verification
  30. This and event objects in event handling in HTML
  31. Introduction to sass or SCSS
  32. Notes on JavaScript object oriented programming
  33. The function of web front page
  34. Implementation of two kinds of file upload Ajax and form + iframe
  35. Loading HTML editor with webkit.net
  36. IOS Development -- Network -- http / nsurlconnection (request, response), HTTP response status code
  37. HTML part -- style attribute;
  38. CSS set a div fixed at the top, not scrolling with the scroll bar
  39. JQuery and$
  40. [web front end] how to build a complete framework of react + mobx + super agent
  41. JavaScript data type detection
  42. Nginx configuration log
  43. Knowledge points of HTML5 and CSS3 (4)
  44. JQuery dynamic display query conditions
  45. 21. The problem of modifying elements when traversing the list
  46. j avascript:Bing Maps AJAX Control, Version 7.0
  47. Some knowledge of Ajax
  48. Bootstrap intelligent form series 10 auto complete component support
  49. < p>& lt;/ p> Why can't tags contain block level tags? What are the special HTML tags?
  50. [transfer] configure Babel in webpack
  51. MySQL master slave delay (excerpt from http://www.linuxidc.com/Linux/2012-02/53995.htm )
  52. React Part 1: building react + nodejs + Express framework
  53. Detailed explanation of behavior expression in IE browser CSS
  54. Solution to the interception of new window. Open() after successful Ajax request
  55. [nginx] configuration
  56. Nginx diagram
  57. JQuery validate plug-in, automatic verification invalid reasons and solutions
  58. JQuery DataTables
  59. CSS3 image scaling
  60. ajax_ for example