当前位置: 首页 > 工具软件 > VuFind > 使用案例 >

接口自动化之requests学习(四)--发送带header的请求

尹善
2023-12-01

实际的接口测试中,请求一般都需要携带headers,下面来说一下接口发送请求时,如何携带headers

#!usr/bin/env python
#-*- coding:utf-8 -*-
"""
@author:Administrator
@file: requests_post.py
@time: 2018/10/13
"""
import requests
import json

data = {"email":"1989898932@163.com",
        'icode':'',
        "autoLogin":"true",
        'origURL':'http://www.renren.com/home',
        'domain':'renren.com',
        "icode":"",
        'key_id':'1',
        'captcha_type':'web_login',
        'password':'123123123',
        'rkey':'d818910ba02fe92c2e1835721e2ca2e2',
        'f':''
        }
url = "http://www.renren.com/ajaxLogin/login?1=1&uniqueTimestamp=2018961914878"
headers = {"Content-Type":"application/x-www-form-urlencoded",
           "User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36",
           "Referer":"http://www.renren.com/"}
r = requests.post(url=url,data=data,headers=headers)

 

 类似资料: