Java setRequestHeader in Python
What is the equivalent of this java statement in python?
post.setRequestHeader("Cookie", jSessionID);
I'm very confused as to whether this is really a cookie or just POST data with a key of 'Cookie'
I have urllib2 and cookielib imported, and am confused.
I开发者_JAVA百科'm also trying to send a file along with the url request, but that is another topic.
Try something like this:
sock = httplib.HTTPConnection('server.com', 80)
data = "op=a_login_attempt"
headers = { "Host":"server.com",
"Content-Type":"application/x-www-form-urlencoded; charset=UTF=8",
"Referer":"server2.com",
"Cookie":"session=12345678",}
sock.request("POST", '/login.php', data, headers)
As you can see "Cookie" is just a key and value in the headers
, which get sent along with the data
using the request()
method. Hope this answers your question.
I would recommend pycurl
精彩评论