[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Luasocket 2.0: socket.http.request using POST
- From: William Trenker <wtrenker@...>
- Date: Wed, 1 Feb 2006 19:27:57 -0800
On 2/1/06, Keith Howe <email@example.com> wrote:
> On 2/1/06, William Trenker <firstname.lastname@example.org> wrote:
> > However, if I add the additional header:
> > ["Content-Type"] = "application/x-www-form-urlencoded"
> > then I get the output "a = 1" indicating the server has now seen the POST body.
> > Any thoughts?
> I'm not exactly sure what the issue is here, as this seems correct to
> me. Without the content-type specified, the web server (and therefore
> PHP script) has no way to interpret the data you are sending in the
> POST body, and its safest option is to simply ignore it entirely. It
> is perfectly legal HTTP to send data in a POST body that is not
> x-www-form-urlencoded, so this header is required if you expect it to
> be interpreted as form data in label=value pairs.
That's what I thought, too. Yet I can't get this to work without the
"Content-Type" header. A quick inspection of the Python urllib2.py
module (includes functionality similar to LuaSocket's
socket.http.request) seems to indicate that the Content-Type header is
data = req.get_data()
if not 'Content-type' in req.headers:
if not 'Content-length' in req.headers:
h.putheader('Content-length', '%d' % len(data))