waveLamn
waveLamn

Reputation: 23

Send a http get request in python

I am trying to send a HTTP get request to "http://192.168.1.236:8081/send.php",code:

params = urllib.urlencode({'content': str(error)})        
head = {'Host': '192.168.1.236', 'User-Agent':  'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:22.0) Gecko/20100101 Firefox/22.0',
'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Language": "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3",
"Accept-Encoding": "gzip, deflate", "Connection":   "keep-alive"}
conn = httplib.HTTPConnection(IP, PORT)
conn.request(method="GET", url="/send.php", body=params, headers=head)
r = conn.getresponse()
print r.read()
conn.close()

Then the print result is 'Array\n(\n)\nmail content empty'.But the result i get by emulating to send the get request in brower with the url "http://192.168.1.236:8081/send.php?content=11212121212121212" is "Array ( [content] => 11212121212121212 ) Array ( ) mail content empty". Who can tell me what the problem is probably.

Upvotes: 1

Views: 374

Answers (1)

MattH
MattH

Reputation: 38255

You probably need to place the params on the URL, GET requests don't typically have bodies as far as I'm aware.

conn.request(method="GET", url="/send.php?%s" % (params,), headers=head)

Upvotes: 2

Related Questions