Cannot get POST to work

T

tedpottel

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
 
F

Falcolas

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
 
P

Piet van Oostrum

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"];
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top