代码实现

import requests
from requests_toolbelt import MultipartEncoder
import urllib.parse
fields = {
'file':("004.jpg",open('004.jpg','rb'),"image/jpeg"), #这里上传的图片是 004.jpg
}

m = MultipartEncoder(fields, boundary='------WebKitFormBoundarynTBa3OWoSMrcVf0F')

headers = {
    'cookie': '', #填写自己登录博客的cookie
    'content-Type': m.content_type,
}
url = 'https://mp.csdn.net/UploadImage?shuiyin=2'
res = requests.post(url, headers=headers, data=m, verify=False)
print(res.json())

这个是我通过抓包获取的csdn博客上传图片的接口,需要个人用户登录,需要cookie

Logo

一站式虚拟内容创作平台,激发创意,赋能创作,进入R空间,遇见同道,让优质作品闪耀发光。​

更多推荐