청크 인코딩 된 데이터를 httpbin.org/post에 POST하려고합니다. 내가 Wireshark를 추적을 분석 할 때마다, 나는 여러 덩어리가 전송되는 보이지 않는 두 경우 모두 HTTPLIB 청크로 인코딩 된 데이터를 파이썬에서 POST하는 방법
#!/usr/bin/env python
import httplib
import os.path
if __name__ == "__main__":
conn = httplib.HTTPConnection('httpbin.org')
conn.connect()
conn.putrequest('POST', '/post')
conn.putheader('Transfer-Encoding', 'chunked')
conn.putheader('Connection', 'Keep-Alive')
conn.putheader('Cache-Control', 'no-cache')
conn.endheaders()
for i in range(130):
conn.send(str(i))
r = conn.getresponse()
print r.status, r.reason
를 사용하여 요청
#!/usr/bin/env python
import requests
def gen():
l = range(130)
for i in l:
yield '%d' % i
if __name__ == "__main__":
url = 'http://httpbin.org/post'
headers = {
'Transfer-encoding':'chunked',
'Cache-Control': 'no-cache',
'Connection': 'Keep-Alive',
#'User-Agent': 'ExpressionEncoder'
}
r = requests.post(url, headers = headers, data = gen())
print r
[HTTP.client가 청크로 인코딩 된 HTTP 본문을 python으로 보내려면 어떻게해야합니까?] (http://stackoverflow.com/q/9237961/95735) –
정말입니까? Wireshark에서 단일 HTTP 메시지를 선택하면 HTTP (Hypertext Transfer Protocol) 부분을 확장 할 수 있습니다. 확장 된 부분에는 데이터가 포함 된 'HTTP 청크 응답'이라는 하위 제목이 있어야합니다. – Lukasa
@ 루카사 : 네, 맞습니다. 어떤 이유로 Wireshark에 청크 데이터가 나타나는 지에 대한 나의 이해가 결함이었습니다. 나는 항상 그것이 분리 된 패킷으로 보인다고 생각했다. 시간 내 줘서 고마워. httplib를 사용하는 –