By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,035 Members | 1,324 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,035 IT Pros & Developers. It's quick & easy.

http post and get the parameter from url

P: 3
Hi,

I have a script client.py as:
Expand|Select|Wrap|Line Numbers
  1. import httplib
  2.  
  3. http = httplib.HTTP("localhost:8081")
  4. data="Welcome to My Page"
  5. http.putrequest("POST", "/cgi-bin/server.py?id="+data)
  6. http.putheader("Host", "localhost:8081")
  7. http.putheader("Content-Type", 'text/plain')
  8. http.putheader("Content-Length", str(len(data)))
  9. http.endheaders()
  10. http.send(data)
  11.  
Server.py:
Expand|Select|Wrap|Line Numbers
  1. import httplib
  2. import cgi
  3.  
  4. print "Content-Type:text/plain"
  5. print
  6.  
  7. id=cgi.FieldStorage()
  8. print id
------------------------------

I got the malformed header from script. Bad header=200: error.

I want to read the posted data from Client.py in Server.py. How do i get the parameter value from the url. Kindly help me.
Feb 23 '09 #1
Share this Question
Share on Google+
1 Reply


sharat87
P: 6
hello,

i'm not sure it would work... but try this

instead of the following two lines in your client.py,
Expand|Select|Wrap|Line Numbers
  1. data="Welcome to My Page"
  2. http.putrequest("POST", "/cgi-bin/server.py?id="+data)
  3.  
do this...

Expand|Select|Wrap|Line Numbers
  1. import urllib
  2. data = "Welcome to my page"
  3. http.putrequest("POST", "/cgi-bin/server.py?id=" + urllib.quote(data))
  4.  
what this does is that it will escape the characters like the (space) in your data in a protocol friendly manner. to undo this escaping, you can use the
Expand|Select|Wrap|Line Numbers
  1. urllib.unquote(s)
  2.  
function

if this does not work.. take a look at the urllib.urlencode function.. that might help ya!

regards,
sharat87
Feb 27 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.