tags:

views:

77

answers:

4

Hi there,

I'm using HTTP POST to call a cgi script on a web server and send along some data as arguments. Some of the arguments can contain quite a bit of data. This seems to be a problem for the web server and I am getting error 414 (Request URI too long) as a result.

My URI ends up looking something like this: http://somewebsite.com/cgi-bin/dosomething.py?function=doitnow&data=this is a lot of data and the server is going to complain...

Is there a different way for me to call a cgi script on a web server and pass it a long string?

Thanks.

+1  A: 

You're not sending your request as a POST if the data is ending up in the URL. With a POST, the request looks like this (incomplete):

POST / HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Content-Length: 10

data=Hello

But the URL would still look like http://somewebsite.com/cgi-bin/dosomething.py.

What does the source of your request look like? The HTML, that is, or however you're putting it together.

Jed Smith
There's nothing intrinsic to the POST method that requires all of the parameter data to be in the body of the request instead of the query string. A browser will do that with form field values, yes. And often you POST things like files that will only work in the body. But it's not true that "if there's data in the URL, it's not a POST request."
Sixten Otto
@Sixten: It's a safe bet, in this case, and it looks like I was right. Point taken, though. :)
Jed Smith
A: 

You need to make a POST request instead of a GET request.

philfreo
A: 

Are you sure you are using POST? Looks like a GET request to me.

<form method="post" action="....py"> <input type="hidden" name="function" value="doitnow"> <input type="hidden" name="data" value="data"> // dont forget the submit button </form>

Jon
+1  A: 

There are several ways to do it, relying on the fact you have access to the CGI that receives the request.

The best option is to send your data as POST instead of GET. If you cannot do this for some reason, you can try to send your data with some sort of compression and decompress it at the CGI.

If the communication occurs between two servers, the first server can save data into a file, and send the filename to second server, so the CGI retrieves this file instead of reading the data from the URL.

You could adapt the CGI to receive the data into chunks, splitting the data and marking each request with some other variable, like function=doitnow&data=bytes&chunk=1&total=2&id=somekey, function=doitnow&data=more-data&chunk=2&total=2&id=somekey

Since I don't really use Python too much, I don't know how to handle POST or GET values, just if is the case, below is a wrapper to pass POST and GET values to a php script:

#!/bin/sh

echo "Content-Type: text/html;"
echo
echo

#POST=`dd count=$CONTENT_LENGTH bs=1 2> /dev/null`
POST=`dd bs=1 2> /dev/null`
php -f 'dosomething.php' -- "$POST" "$QUERY_STRING"
Ast Derek