Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Cannot get POST to work

Reply
Thread Tools

Cannot get POST to work

 
 
tedpottel@gmail.com
Guest
Posts: n/a
 
      09-29-2009
Hi,
I'm trying to post data to a short test script in php I wrote.
The python code to do the post is
import httplib

#server address
conn = httplib.HTTPConnection("localhost")

#file location
conn.request("POST", "/programming/bots/test.php","&ted=fred")
r1 = conn.getresponse()
print r1.status, r1.reason
data1 = r1.read()
print data1
conn.close()
print "new ok"

The PHP script is
print"hello <br>";
print $_POST["ted"];

Ted post
 
Reply With Quote
 
 
 
 
Falcolas
Guest
Posts: n/a
 
      09-29-2009
On Sep 29, 10:24*am, "(E-Mail Removed)" <(E-Mail Removed)>
wrote:
> Hi,
> I'm trying to post data to a short test script in php I wrote.
> The python code to do the post is
> import httplib
>
> #server address
> conn = httplib.HTTPConnection("localhost")
>
> #file location
> conn.request("POST", "/programming/bots/test.php","&ted=fred")
> r1 = conn.getresponse()
> print r1.status, r1.reason
> data1 = r1.read()
> print data1
> conn.close()
> print "new ok"
>
> The PHP script is
> print"hello <br>";
> print $_POST["ted"];
>
> Ted post


I can't speak to what is wrong with your current script - instead I
would recommend the higher level urllib libraries:

(Untested)
import urllib2, urllib

response = urllib2.open("http://localhost/programming/bots/test.php",
urllib.urlencode({"ted": "fred"}))
print response.read()
response.close()

~Garrick
 
Reply With Quote
 
 
 
 
Piet van Oostrum
Guest
Posts: n/a
 
      09-30-2009
>>>>> "(E-Mail Removed)" <(E-Mail Removed)> (t) wrote:

>t> Hi,
>t> I'm trying to post data to a short test script in php I wrote.
>t> The python code to do the post is
>t> import httplib


>t> #server address
>t> conn = httplib.HTTPConnection("localhost")


headers = {"Content-type": "application/x-www-form-urlencoded",
"Accept": "text/plain"}

>t> #file location
>t> conn.request("POST", "/programming/bots/test.php","&ted=fred")


conn.request("POST", "/programming/bots/test.php", "ted=fred", headers)

>t> r1 = conn.getresponse()
>t> print r1.status, r1.reason
>t> data1 = r1.read()
>t> print data1
>t> conn.close()
>t> print "new ok"


>t> The PHP script is
>t> print"hello <br>";
>t> print $_POST["ted"];


>t> Ted post


--
Piet van Oostrum <(E-Mail Removed)>
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why "Welcome Message" I post come get posted as the reply to same post ? arnuld C++ 6 09-05-2007 05:24 PM
Cannot get past POST screen John Orrett Computer Support 11 01-01-2007 05:59 PM
I CANNOT buy anything over the web & CANNOT get any email from ANY client of mine - HELP!! fourstriper Computer Support 9 12-20-2005 09:39 PM
Post post post. Shel-hed Computer Support 2 11-08-2003 07:41 AM
"The system cannot find the file specified." when invoking method ~HTTP Get/Post C Jones ASP .Net Web Services 0 07-10-2003 11:56 AM



Advertisments