473,405 Members | 2,349 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,405 software developers and data experts.

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.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0})
headers = {"Content-type": "application/x-www-form-urlencoded"}
conn = httplib.HTTPConnection("somelocation")
conn.request("POST", "/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&eggs=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("POST", "/cgi-bin/query?spam=1&eggs=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&bacon.

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

Thanks,
Vincent

Jul 18 '05 #1
2 1524
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.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0})
headers = {"Content-type": "application/x-www-form-urlencoded"}
conn = httplib.HTTPConnection("somelocation")
conn.request("POST", "/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&eggs=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&bacon.


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.read() should do the
trick).

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

params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0})
conn = httplib.HTTPConnection("somelocation")
conn.request("GET", "/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.EDU> wrote:
after them, actually). To retrieve them in your do_POST() method, you
have to read them from self.rfile (self.rfile.read() 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
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/...
10
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...
16
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...
2
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...
10
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...
1
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...
0
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...
4
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...
10
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.......
2
by: =?Utf-8?B?U2Fs?= | last post by:
<I MOVED THIS POST TO ITS OWN THREAD. ORIGINAL POST FOUND HERE:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.