添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
深沉的黄豆  ·  FOR JSON ...·  2 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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.

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.

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 Nov 12, 2009 at 3:15 @Sixten: It's a safe bet, in this case, and it looks like I was right. Point taken, though. :) – Jed Smith Nov 12, 2009 at 3:19

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;"
#POST=`dd count=$CONTENT_LENGTH bs=1 2> /dev/null`
POST=`dd bs=1 2> /dev/null`
php -f 'dosomething.php' -- "$POST" "$QUERY_STRING"

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>

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.