开发者

Java setRequestHeader in Python

开发者 https://www.devze.com 2023-01-24 13:32 出处:网络
What is the equivalent of this java statement in python? post.setRequestHeader(\"Cookie\", jSessionID);

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

0

精彩评论

暂无评论...
验证码 换一张
取 消