简体   繁体   English

Python HTTP标头内容类型边界

[英]Python HTTP Header Content-Type boundary

Here is my code: 这是我的代码:

headers={
'Host': 'cafe.upphoto.naver.com',
'Content-Length': '879990',
'Accept': '*/*',
'Origin': 'http://cafe.upphoto.naver.com',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36',
'Content-Type':content,
'Content-Type': 'multipart/form-data;',# boundary=----WebKitFormBoundary3oLjjtLvU7AzQqTF',
'Referer': write,
'Accept-Language': 'ko-KR,ko;q=0.8,en-US;q=0.6,en;q=0.4',
}

files = {'image':('test.jpg',open('C:\\Users\\Public\\Pictures\\Sample Pictures\\test.jpg','rb'),'Content-Type: image/jpeg'),'filename':(None,'test.jpg'),'autorotate':(None,'true'),'extractAnimatedCnt':(None,'true'),'userId':(None,'beg1995')}

resp=self.post(url2+'upload/0',files=files,headers=headers)

When you run this code, the following packet is created: 当您运行此代码时,将创建以下数据包:

POST http://cafe.upphoto.naver.com/MjAxNzA3MDcwMTExNDAHMTQ5OTM1ODQzNjkyNwdjYWZlMgdiZWcxOTk1BzAHMgdhODA1MzhiZmMyMGMyYTFlYTlhODE1NGY5OTc1ZDRkZA/upload/0 HTTP/1.1
Host: cafe.upphoto.naver.com
Proxy-Connection: keep-alive
Content-Length: 879990
Accept: */*
Origin: http://cafe.upphoto.naver.com
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary9xhUsyQOPYJrPr3R
Referer: http://cafe.upphoto.naver.com/MjAxNzA3MDcwMTExNDAHMTQ5OTM1ODQzNjkyNwdjYWZlMgdiZWcxOTk1BzAHMgdhODA1MzhiZmMyMGMyYTFlYTlhODE1NGY5OTc1ZDRkZA/startup?mode=base&width=960
Accept-Language: ko-KR,ko;q=0.8,en-US;q=0.6,en;q=0.4

--e2f306a6b5a3485fb70bc2f7f1af2e9a
Content-Disposition: form-data; name="image"; filename="test.jpg"
Content-Type: Content-Type: image/jpeg

ÿØÿà

Content-Disposition: form-data; name="filename"

test.jpg
--e2f306a6b5a3485fb70bc2f7f1af2e9a
Content-Disposition: form-data; name="autorotate"

true
--e2f306a6b5a3485fb70bc2f7f1af2e9a
Content-Disposition: form-data; name="extractAnimatedCnt"

true
--e2f306a6b5a3485fb70bc2f7f1af2e9a
Content-Disposition: form-data; name="userId"

beg1995
--e2f306a6b5a3485fb70bc2f7f1af2e9a-

Look. 看。 The boundaries set and the boundaries actually applied are different. 边界集和实际应用的边界不同。

What is the problem? 问题是什么?

I suppose you use requests library. 我想您使用请求库。 It doesn't allow to setup boundaries. 它不允许设置边界。 So it is generated automatically on the fly. 因此它是即时动态生成的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Ajax,内容类型标头和python - Ajax, content-type header and python Python 请求不发送 {"Content-Type":"application/json"} 标头或只是忽略 HTTP POST 中的正文 - Python requests not sending {"Content-Type":"application/json"} header or is just ignoring body in HTTP POST 使 Python http.server 对 webp 图像使用正确的内容类型 header - Make Python http.server use correct content-type header for webp images 如何为304 http响应代码设置Content-Type标头? - How to set Content-Type header for 304 http response code? HTTP 响应不包含“Content-Type”标头 - HTTP Response does not contain a 'Content-Type' header 如何从 HTTP 标头响应中解析 Content-Type 的值? - How to parse the value of Content-Type from an HTTP Header Response? 如何检测和更正 python 中电子邮件标题中的 Content-Type 字符集? - How to detect and correct the Content-Type charset in email header in python? 基于Content-Type标头的Python / Django REST Framework POST - Python/Django REST Framework POST based on Content-Type header "如何使用 python 请求设置内容类型的边界?" - How can I set boundary of Content-type using python requests? 在Python中更改内容类型 - Changing Content-Type in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM