data请求 添加cookies

data请求 添加cookies

代码:

 

# 请求参数中添加cookies信息
# 聊一下cookies
# 举例说明,添加地址的接口
'''
添加地址接口
接口信息:
url:http://106.12.126.197/fanwe/member.php?ctl=uc_consignee&act=save_consignee&fhash=KsSSLvzmXvCruopmaIYizaMHjARJUtwfRLGrDYAJFTojmYUgOJ
请求参数:
consignee: 111
address: 222
mobile: 13111111111
ajax: 1
id:
请求方式:post
返回结果:{"status":1,"info":"\u4fdd\u5b58\u6210\u529f","jump":""}
记住公司里面直接跟开发要接口文档,(尽量不要抓包,很多时候前端界面是没有开发完成的,无法实现抓包)
http://106.12.126.197/fanwe/
http://106.12.126.197/fanwe/index.php?ctl=licai&act=uc_published_lc    admin --我的理财
账户管理--收货地址--添加配送地址
'''
import requests
url = "http://106.12.126.197/fanwe/member.php?ctl=uc_consignee&act=save_consignee&fhash=KsSSLvzmXvCruopmaIYizaMHjARJUtwfRLGrDYAJFTojmYUgOJ"

data = {
    "consignee": "111",
    "address": "222",
    "mobile": "13111111111",
    "ajax": 1,
    "id":""
}

# 提示请先登录,权限校验的问题,如果直接添加成功,就是一个bug
# 问题,没有携带用户辨明信息,cookies
# 工作当中,如果接口需要哪些cookies值,咨询后端开发人员,只需要

cookies = {
    "PHPSESSID":"0p4et5kgiscqmua50ru7as8j30"
}
# 发送接口请求中,如何去添加用户辨明信息:cookies
r = requests.post(url= url,data = data,cookies = cookies)
print(r.encoding)
print(r.text.encode("utf-8").decode('unicode_escape'))  # 先把返回的结果转换成utf-8,再去解码成中文的编码


'''
General:
Request URL: http://106.12.126.197/fanwe/member.php?ctl=uc_consignee&act=save_consignee&fhash=KsSSLvzmXvCruopmaIYizaMHjARJUtwfRLGrDYAJFTojmYUgOJ
Request Method: POST
Status Code: 200 OK
Remote Address: 106.12.126.197:80
Referrer Policy: no-referrer-when-downgrade

response headers  view source
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection: Keep-Alive
Content-Length: 56
Content-Type: text/html; charset=utf-8
Date: Wed, 13 May 2020 14:44:07 GMT
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive: timeout=5, max=100
Pragma: no-cache
Server: Apache/2.4.6 (CentOS) PHP/5.4.16
Set-Cookie: PHPSESSID=0p4et5kgiscqmua50ru7as8j30; path=/; HttpOnly
X-Powered-By: PHP/5.4.16
Accept: application/json, text/javascript, */*; q=0.01
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: keep-alive
Content-Length: 55
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Cookie: PHPSESSID=0p4et5kgiscqmua50ru7as8j30
Host: 106.12.126.197
Origin: http://106.12.126.197
Referer: http://106.12.126.197/fanwe/member.php?ctl=uc_consignee
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36
X-Requested-With: XMLHttpRequest
ctl: uc_consignee
act: save_consignee

fhash: KsSSLvzmXvCruopmaIYizaMHjARJUtwfRLGrDYAJFTojmYUgOJ

consignee: 111
address: 222
mobile: 13111111111
ajax: 1
id: 


'''

 

posted @ 2020-12-14 10:34  ss120369192  阅读(151)  评论(0)    收藏  举报