HttpRunner automation request with headers interface and send POST request

headers

You can add header information through headers, as shown below

# 发送请求头headers的接口
- config:
    name: 百度接口用例
    base_url: https://www.baidu.com

- test:
    name: 发送百度接口的头部信息
    request:
      url: /s
      method: GET
      headers:
        Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
        Accept-Encoding: gzip, deflate, br
        Accept-Language: zh-CN,zh;q=0.9
        Cache-Control: max-age=0
        Connection: keep-alive
        User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36
      params:
          wd: 猫
    validate:
      - eq: [status_code,200]

POST request

Send a POST request to select json/data/body/ to add data through the sent data

# 发送POST请求
- config:
    name: 用户标签管理
    base_url: https://api.weixin.qq.com

- test:
    name: 创建用户标签
    request:
      url: /cgi-bin/tags/create
      method: POST
      params:
        access_token: 49_lke8tpYCU4h5JhQtM5vHyT-7l4MBgmetqyUAczzD0z1kpZGjtmQNdEahThSG5458ET3ytgrXtfZmz4PzuQWqLUkAR8_kqI-jpPusfixbFj_2KWXzJIBlrI_Ay9zt-o3427UxRYR3xdKryeR8CZZaAGAPMM
      json:
        {"tag":{"name":"河南abc"}}
    validate:
      - eq: [status_code,200]

Practical case

Optical theory is useless, you have to learn to follow along, and you have to do it yourself, so that you can apply what you have learned to practice. At this time, you can learn from some actual combat cases.

If it is helpful to you, please like and collect it to give the author an encouragement. It is also convenient for you to quickly find it next time.

If you don’t understand, please consult the small card below. The blogger also hopes to learn and progress with like-minded testers

At the right age, choose the right position, and try to give full play to your own advantages.

My road of automated test development is inseparable from the plan of each stage along the way, because I like planning and summarizing,

Test and develop video tutorials, study notes and receive portals! ! !

Guess you like

Origin blog.csdn.net/Liuyanan990830/article/details/131563249