1

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.

2
  • what is the value of str(error) when you use then in urllib.urlencode? Commented Jul 26, 2013 at 10:36
  • error is a object of type 'str' Commented Jul 27, 2013 at 1:45

1 Answer 1

2

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)
Sign up to request clarification or add additional context in comments.

2 Comments

what about doing http post request using the function conn.request?
@waveLamn As long as the target URL supports both POST and GET requests, either should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.