• python3+requests get/post 请求


    1.get请求

    (1)没有请求参数类型

    1 response = requests.get(url='')
    2 print(response.text)

    (2)有请求参数的类型(键值对形式表示参数)

    1 response = requests.get(url='',params={'key1':'value1','key2':'value2'})
    2 print(response.text)

    (3)有请求头(键值对形式表示请求头)

    1 response = requests.get(url='',headers={'key1':'value1'})
    2 print(response.text)

    2.post请求

    (1)请求正文是application/x-www-form-urlencoded

    1 requests.post(url='',data={'key1':'value1','key2':'value2'},headers={'Content-Type':'application/x-www-form-urlencoded'})

    (2)请求正文是multipart/form-data

    1 requests.post(url='',data={'key1':'value1','key2':'value2'},headers={'Content-Type':'multipart/form-data'})

    (3)请求正文是raw

    传入xml格式文本
    1 requests.post(url='',data='<?xml  ?>',headers={'Content-Type':'text/xml'})
    传入json格式文本
    1 requests.post(url='',data=json.dumps({'key1':'value1','key2':'value2'}),headers={'Content-Type':'application/json'})

    或者

    1  requests.post(url='',json={{'key1':'value1','key2':'value2'}},headers={'Content-Type':'application/json'})

    (4)请求正文是binary

    1 requests.post(url='',files={'file':open('test.xls','rb')},headers={'Content-Type':'binary'})

     转载请注明出处:https://www.cnblogs.com/shapeL/p/9037035.html

     
     
  • 相关阅读:
    性能测试概念
    接口测试概念
    SQL多表查询
    手机App测试概念
    App测试页面滑动
    自动化测试概念
    Monkey 命令
    Tomcat+JDK安装和配置
    Linux系统FTP安装、安装和使用
    Web测试方法(一)
  • 原文地址:https://www.cnblogs.com/xiohao/p/11198667.html
Copyright © 2020-2023  润新知