473,722 Members | 2,161 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

http POST question

Please tell me if this is true or not..

In a all my applications I used the old fashioned way of "POST" requests:
params = urllib.urlencod e({'spam': 1, 'eggs': 2, 'bacon': 0})
headers = {"Content-type": "applicatio n/x-www-form-urlencoded"}
conn = httplib.HTTPCon nection("somelo cation")
conn.request("P OST", "/cgi-bin/query", params, headers)

Now, without thinking.. have to admit.. I always thought that the request object would format
this request into something like: /cgi-bin/query?spam=1&eg gs=2&bacon=0

Until yesterday when I needed a bare bone BaseHTTPServer, creating my own do_POST:

def do_POST(self):
print self.path

there were no spam, bacon and eggs in "self.path" . They are only there when I change conn.request in:
conn.request("P OST", "/cgi-bin/query?spam=1&eg gs=2&bacon=0", params, headers)

Sniffing on the network learned me that my params are in the header, not in the post request and look like: spam=1&eggs=2&b acon.

So, is it indeed true that I misunderstood the formatting?

Thanks,
Vincent

Jul 18 '05 #1
2 1534
On Wed, 14 Jul 2004, Raaijmakers, Vincent (GE Infrastructure) wrote:
In a all my applications I used the old fashioned way of "POST" requests:
params = urllib.urlencod e({'spam': 1, 'eggs': 2, 'bacon': 0})
headers = {"Content-type": "applicatio n/x-www-form-urlencoded"}
conn = httplib.HTTPCon nection("somelo cation")
conn.request("P OST", "/cgi-bin/query", params, headers)

Now, without thinking.. have to admit.. I always thought that the
request object would format this request into something like:
/cgi-bin/query?spam=1&eg gs=2&bacon=0
You're confusing POST with GET:
Sniffing on the network learned me that my params are in the header, not
in the post request and look like: spam=1&eggs=2&b acon.


The POST method places its parameters in the header of the request (just
after them, actually). To retrieve them in your do_POST() method, you
have to read them from self.rfile (self.rfile.rea d() should do the
trick).

If you'd rather pass the parameters in the URL, you have to use the GET
method:

params = urllib.urlencod e({'spam': 1, 'eggs': 2, 'bacon': 0})
conn = httplib.HTTPCon nection("somelo cation")
conn.request("G ET", "/cgi-bin/query?" + params)

Then you can retrieve them in the do_GET() method of your server, using
self.path.

Jul 18 '05 #2
On Wed, 14 Jul 2004 10:38:29 -0400, Christopher T King
<sq******@WPI.E DU> wrote:
after them, actually). To retrieve them in your do_POST() method, you
have to read them from self.rfile (self.rfile.rea d() should do the
trick).


You should read just "content-length" bytes because otherwise you
may get stuck waiting forever.

Andrea
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
17132
by: Gary Petersen | last post by:
For the benefit of others, I want to show how to do an HTTP POST request using fsockopen(). I banged my head against a wall for two days trying to figure this out. I even went to http://php.net/ to find out how to do this, but it didn't help because my mind automagically converted the "Content-Length" header into "Length." I even went to http://www.ietf.org/ to find out the specific protocol for HTTP POSTs, but I didn't
10
3262
by: Dave Smithz | last post by:
Hi there, I have a situation where I want to have multiple submit buttons on the same form and therefore want to use a redirection php script that checks the value associated with the submit form variable to calculate which submit was pressed and then redirects the user to another php page accordingly. I used: headers ("location:myphpscript.php")
16
2598
by: Andy Lai | last post by:
Hi, I am writing a C++ program which needs to post an XML to an HTTP server periodically and the program will run on different platforms including w32, linux, and unix. I see that there are some library available out there including cURL and Libwww from w3c. I will spend some time on them myself but if anyone are familiar with them, please share know how good they compile/run on different platforms. Also, if there is a better HTTP
2
1183
by: Steve Lloyd | last post by:
Hi, This is bit of an open question and is more of a theoretical one that an actual coding question but would appreciate some pointers I want to send some data to an external server that will launch a process on that server and receive some sort of acknowlegment using a HTTP POST without the client browser being aware of the post and the source of the post being the webserver (used for an IP check).
10
3434
by: glenn | last post by:
I am use to programming in php and the way session and post vars are past from fields on one page through to the post page automatically where I can get to their values easily to write to a database or continue to process on to the next page. I am now trying to learn ASP to see if we can replace some of our applications that were written in php with an ASP alternative. However, after doing many searches on google and reading a couple...
1
4263
by: David | last post by:
I need to redirect to a page and HTTP Post data. The Response.Redirect does not work and the HTTPREQUEST option calls the page and waits for a response, but I need to transfer control to the page. Eg. Redirect and POST data. The only way I can see to do this is to format a HTML/POST, with Javascript, page and use the RESPONSE.WRITE option. Thanks
0
1826
by: Owen | last post by:
Hello everyone, I am using VS.NET 2003(Trandition Chinese) Edition, and httpLook software for checking http requests. I found a problem that the following programs don't really "POST". These programs can be successfully compiled. There is no error message shown at running also. But the httpLook confirms that the program doesn't post. -- Here is the HTTP request acquired by the software: ---
4
2804
by: Bob Bedford | last post by:
Hi all, I'm trying to submit the google sitemap after it has been created on my server with PHP. Here is the code: <?php $address= urlencode('www.mysite.com/sitemap.gz');?> <form name="submitsitemap" method="POST" action="http://www.google.com/webmasters/sitemaps/ping?sitemap=<?php echo $address;?>"></form> <script>submitsitemap.submit();</script>
10
3232
by: rup | last post by:
Hello, This is my first application on socket programming in vc++. I am facing problem that how to make connection to server, & make GET/POST request by HTTP. Please help me. Its urgent.... Thanks
2
4533
by: =?Utf-8?B?U2Fs?= | last post by:
<I MOVED THIS POST TO ITS OWN THREAD. ORIGINAL POST FOUND HERE: http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.dotnet.framework.webservices&mid=22d09e8e-4390-46b2-b266-ff37405d68ba > I've been searching around the forums for answers to this but not finding anything substantial. My env is XP Pro / .NET 2.0. The web service in question is written in Java on a WebLogic box. I can open the wsdl in IE...
0
8863
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9384
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9238
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9157
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
4502
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3207
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2602
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2147
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.