Quantcast
Channel: Planet Python
Viewing all articles
Browse latest Browse all 22462

Jim Hughes: Cookies with httplib

$
0
0

I needed to do a simple http get in the other day, the only catch was that I had to send a cookie. My first thoughts were that this might be tricky, but in practise it's a doddle. Below is a simplistic example passing a cookie (called "Fish", with a value of "Cod") using Python's httplib.

import httplib
conn = httplib.HTTPConnection( "www.example.com" )
Headers = {"Cookie" : "Fish=Cod"}
conn.request("GET", "/fishfinder.html", None, Headers )
response = conn.getresponse()
data = response.read()

How hard can it be?


Viewing all articles
Browse latest Browse all 22462

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>