lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I've been having problems getting at least 2 web servers (Apache
mod-php, and lighttpd with fastcgi php support) to accept request data
using the POST method.

Consider (using Lua 5.1rc with LuaSockets 2.0 compiled in):

require'socket.http'
response_body = socket.http.request("http://mysite.com/test.php","a=1";)
print(response_body)

with test.php on the server:

<?php
if (!isset($_POST['a'])) { echo "No a in POST data\n"; }
else { echo "a = ".$_POST['a']."\n"; }
?>

When run, the lua script prints "No a in POST data" indicating that
the "a=1" wasn't seen by the server.

The same thing happens when I use the table version:

require'socket.http'
require'ltn12'
response_body = {}
request_body = "a=1"
socket.http.request{
    url = "http://mysite.com/test.php";,
    method = "POST",
    headers = {
         ["Content-Length"] = string.len(request_body)
     },
     source = ltn12.source.string(request_body),
     sink = ltn12.sink.table(response_body)
}
table.foreach(response_body,print)

Again I get "No a in POST data".

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?

Cheers,
Bill