Fiddler的使用
接口基础知识
根据fiddler捕获接口,分析并编写对应接口测试
测试慕课网账号更换头像的接口
1.先对接口进行抓取
打开fiddler everywhere
来到慕课网个人页面
更换头像
更换头像后
Fiddler抓取到的页面,找到其中的发送请求
根据body值,判断出发送头像的接口
这里乱码,猜测是因为头像为文件,作为值显示时,会乱码
老版的显示为
通过该URL进行编写代码
https://www.imooc.com/user/postpic
根据发送请求的参数对post进行编写
Content-Disposition: form-data; name="fileField"; filename="Snipaste_2024-06-16_12-57-52.jpg" Content-Type: image/jpeg=����
确定filefield的形式
根据对应的操作,找到对应的、所需要的数据
需要两种数据
- 第一个是 name=“fileField”, type = “file”, 接受的类型也给出
- 第二个是 name=“type”, value=”1”
进行代码编写
#coding=utf-8 import requests import json #上传文件 url = 'https://www.imooc.com/user/postpic' # file = { # "fileField":("文件名称",open("路径","rb"),"image/jpg"), # "type":"1" # } file = { "fileField":("Snipaste_2024-06-16_12-57-52.jpg",open("D:/Document/Snipaste_2024-06-16_12-57-52.jpg","rb"),"image/jpg"), "type":"1" } res = requests.post(url, files=file, verify=False).text print(res) res = requests.post(url, files=file, verify=False).json() print(res)
结果
{"result":0,"data":"","msg":"\u8bf7\u767b\u5f55"} {'result': 0, 'data': '', 'msg': '请登录'}
说明没有登录,无法上传图片
使用cookie,来
修改代码,再次上传
#coding=utf-8 import requests import json #上传文件 url = 'https://www.imooc.com/user/postpic' # file = { # "fileField":("文件名称",open("路径","rb"),"image/jpg"), # "type":"1" # } file = { "fileField":("Snipaste_2024-06-19_19-47-41.jpg",open("D:/Document/Snipaste_2024-06-19_19-47-41.jpg","rb"),"image/jpg"), "type":"3" } cookie = { "apsid":"llMjQ5ZDg3OTNkODExNjJmNjBkNWE4Mzk4Mzg1MGQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANzI4MjExNgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAyMzExMTI5MDQ5M0BxcS5jb20AAAAAAAAAAAAAAAAAADQ4Y2VjYzZkMzAzOTM3MDhiMDVjNmU0MmQ1MzljZGM4qwFxZ%2BqWHGM%3DZD" } res = requests.post(url, files=file, cookies=cookie, verify=False).text print(res) # with open("mukewang.apk","wb") as f: # f.write(res.content) #res = requests.post(url,files=file,cookies=cookie,verify=False).json() # print(res) # #res = requests.post(url,files=file,cookies=cookie,verify=False).json() # print(res)
结果
{"result":1,"data":{"key":"67710ded0001738b03050458","imgpath":"\/\/img1.sycdn.imooc.com\/67710ded0001738b03050458.jpg"},"msg":""}
将url复制到地址栏
果然为上传的图片
本文作者:清澈的澈
本文链接:https://www.cnblogs.com/lmc7/p/18640812
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步