import requests
url = "
http://yk-project.dev.ethercap.com/report/add"
querystring = {"_":"1111111"}
payload = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"_csrf\"\r\n\r\nBr0949bZlNP4o4iGtNkbE1uE6XU903CqrI9ZnZRQzJF_zEi0n-_g5Zmay_T7qkNYPbbdGVGGRtzA6Qn15Rae6A==\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"ReportForm[url]\"; filename=\"齐家网 COO 毛新勇:《未来平台赋能是必然,但要真刀真枪才有意义》-18 页.pdf\"\r\nContent-Type: application/pdf\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--"
headers = {
'content-type': "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
'User-Agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36",
'Cookie': "u=400; PHPSESSID=dfc4ac95c5c485a49ec167febc0b2da6; _csrf=0226ebc29a0710864db49376b6c400a3895ce0dbfb7161dc3d08e5bc8d148386a%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22_csrf%22%3Bi%3A1%3Bs%3A32%3A%22aoSW7OAr9i2rwVb2H7Khty6qSimxBUMn%22%3B%7D",
'Cache-Control': "no-cache",
'Postman-Token': "64fd1e6e-e442-4161-b32e-110c6627ee23"
}
response = requests.request("POST", url, data=payload, headers=headers, params=querystring)
print(response.text)
自己复制后改成下列形式 我写绝对路径和相对路径都报错空文件,请指教,这是为啥? 完全复制 postman 的
url = "
http://yk-project.dev.ethercap.com/report/add"
querystring = {"_": "1111111"}
payload = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"_csrf\"\r\n\r\n{}\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"ReportForm[url]\"; filename=\"{}\"\r\nContent-Type: application/pdf\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--".format(csrf_token,'麦肯锡中国银行业 CEO 季刊-2018 年冬季刊精简版-137 页.pdf')
print(payload.encode('utf-8'))
headers = {
'content-type': "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
'User-Agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36",
'Cookie': "u=400; PHPSESSID=dfc4ac95c5c485a49ec167febc0b2da6; _csrf=0226ebc29a0710864db49376b6c400a3895ce0dbfb7161dc3d08e5bc8d148386a%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22_csrf%22%3Bi%3A1%3Bs%3A32%3A%22aoSW7OAr9i2rwVb2H7Khty6qSimxBUMn%22%3B%7D",
'Cache-Control': "no-cache",
'Postman-Token': "64fd1e6e-e442-4161-b32e-110c6627ee23"
}
response = requests.request("POST", url, data=payload.encode('utf-8'), headers=headers, params=querystring)