简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM