[Tutor] POST request using httplib2

naheed arafat naheedcse at gmail.com
Thu Jun 30 06:29:54 CEST 2011


On the way of learning " handling POST request in php" i tried to make a
simple python http client using httplib2 & urllib module.. what i wanted to
do was submitting username & password field to a php script (which just
echo's the username & password)  & prints the response in python,not in
html/php..

import httplib2
import urllib
url="http://localhost/form_process.php"
body={'username':'xyz','password':'abc'}
h=httplib2.Http()
response,content=h.request(url,'POST',urllib.urlencode(body))
print content

I got the following content:

*<html>
<head><title>Form processing</title></head>
<body>
: </body>
</html>*


instead of:

*<html>
<head><title>Form processing</title></head>
<body>
xyz: abc</body>
</html>*

attachments:
form.php # takes username,password from the user,pass those to
              # form_process.php as GET parameter
form_process.php # echo username,password.

sorry for my long email.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110630/8dd15559/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: form.php
Type: application/x-httpd-php
Size: 406 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20110630/8dd15559/attachment.php>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: form_process.php
Type: application/x-httpd-php
Size: 175 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20110630/8dd15559/attachment-0001.php>


More information about the Tutor mailing list