python - How to send http body without the 'POST / HTTP/1.1' header using pycurl? -


i send data mysockserver listening on socket , expecting data follows

packet='a'+struct.pack("!i", 98)+"hello world blah blah" 

it works fine. need send above data above socket sitting behind http mytcpipserver.com. mytcpipserver.com redirecting messages mysockserver. tried following

csocket = pycurl.curl() csocket.setopt(pycurl.url, 'https://mytcpipserver.com:443') csocket.setopt(pycurl.proxy, 'myproxy.com:8080') csocket.setopt(pycurl.proxyport, 8080) csocket.setopt(pycurl.verbose, 1) csocket.setopt(pycurl.httpproxytunnel, 1) headers = ['post', 'expect: ', 'user-agent: ', 'host:', 'accept:', 'content-length:', 'content-type:'] csocket.setopt(pycurl.httpheader, headers) header = "a" + struct.pack("!i", len(message)) packet = header + message csocket.setopt(pycurl.postfields, packet) csocket.perform() 

i can see msg reaching mysockserver follows want see server receiving raw data i.e. 'a'+struct.pack("!i", 98)+"hello world blah blah"

"post / http/1.1  a<rest of message>" 

mysockserver not expecting arrived msg start post a+packedinteger+moredata. basically, how send raw data without header?

so question is, how send body without header "post / http/1.1"?

don't use pycurl, directly use socket module. pycurl sending http requests, , server not http server, integer you're getting part of raw post request:

>>> binascii.unhexlify(hex(1330861088)[2:]) 'ost ' 

simple example how should work:

import socket  packet='a'+struct.pack("!i", 98)+"hello world blah blah" conn = socket.create_connection(('target_host', target_port)) conn.send(packet) # ... conn.close() 

also, you're trying dump binary data using json.dumps, json per definition uses unicode, won't work, , not want.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -