473,698 Members | 1,947 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 1533
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
17129
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
3261
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
2595
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
1178
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
3428
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
4259
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
1825
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
2802
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
3231
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
4527
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
8600
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9018
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
8890
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
7711
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5859
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4360
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
4614
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3038
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

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.