473,387 Members | 1,592 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

http post and get the parameter from url

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
1 3465
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

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

Similar topics

1
by: SPG | last post by:
Hi, I have a servlet application that I am trying to write a very basic load tester for. There application has several servlets, but all rely on the same session being used (IE: For logged in...
8
by: turnit \(removethis\) | last post by:
I have a login form that uses the post method to carry the information to the next page. The form works just fine in ie6.0, but fails in mozilla and fails in ie5.2 on a mac. "HTTP/1.1 400 Bad...
3
by: Geoff | last post by:
I have been asked to add postal rates to a web page shopping cart checkout procedure. After contacting the post office I discovered that they used XML to receive postal rate requests and send back...
3
by: news.onet.pl | last post by:
Hello I'm biting into the following problem: HTTP is stateless protocol and thus net languages' designer had to find out session. As far as I know session handling in any of the language (PHP,...
1
by: Henrik Holle | last post by:
Hi, i make an http get request like http://myUrl/Test.aspx?myID=test After this Request i excecute a http-post, but after this post my Url looks same like after the http-get. I need to remove...
2
by: SM | last post by:
Hi, I have a web service method developed in .Net 1.1 where both http get and post protocols are enabled. the problem is that , when i access my web method from ie window like...
2
by: =?Utf-8?B?cGhlbmdsYWk=?= | last post by:
I am not sure really how to explain this but here goes. I am creating some new web services and I want to be able to post data like the following: <Data> <some value>1</some value> <more...
1
by: jaymehta | last post by:
hello friends, I am making one program in c#.net(window application) and i had made one form that accept one input i.e. no of tickets and i had specified 4 as input. There is one website on the...
6
by: squishywaffle | last post by:
This has got me somewhat stumped, so I'll throw it up here in hopes that someone has ran into this before. I'm trying to send a MIME package to Esko Backstage. I'm a bit confused as to how to send...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.