HTTP POST 错误 414

发布于 2024-08-10 21:32:49 字数 406 浏览 2 评论 0原文

我使用 HTTP POST 调用 Web 服务器上的 cgi 脚本并发送一些数据作为参数。有些参数可能包含相当多的数据。这似乎是 Web 服务器的问题,结果我收到错误 414(请求 URI 太长)。

我的 URI 最终看起来像这样: http://somewebsite.com/cgi-bin/dosomething。 py?function=doitnow&data=this 是大量数据,服务器会抱怨...

是否有其他方法可以让我在 Web 服务器上调用 CGI 脚本并向其传递一个长字符串?

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

小红帽 2024-08-17 21:32:50

如果数据以 URL 结尾,则您不会以 POST 方式发送请求。使用 POST 时,请求看起来像这样(不完整):

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

data=Hello

但是 URL 仍然看起来像 http://somewebsite.com/cgi-bin/dosomething.py

您的请求的来源是什么样的? HTML,即 HTML,或者您将其组合在一起的方式。

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.

但可醉心 2024-08-17 21:32:50

有多种方法可以做到这一点,具体取决于您有权访问接收请求的 CGI。

最好的选择是将您的数据作为POST而不是GET发送。如果由于某种原因无法执行此操作,您可以尝试使用某种压缩方式发送数据,并在 CGI 处对其进行解压缩。

如果通信发生在两个服务器之间,第一个服务器可以将数据保存到文件中,并将文件名发送到第二个服务器,因此CGI检索该文件而不是从URL读取数据。

您可以调整 CGI 以将数据接收为块,分割数据并使用其他变量标记每个请求,例如 function=doitnow&data=bytes&chunk=1&total=2&id=somekey, function=doitnow&data=more-data&chunk=2&total=2&id=somekey

由于我不太使用Python,所以我不知道如何处理 POST或 GET 值,如果是这种情况,下面是将 POST 和 GET 值传递给 php 脚本的包装器:

#!/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"

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"
江城子 2024-08-17 21:32:50

您需要发出 POST 请求而不是 GET 请求。

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

因为看清所以看轻 2024-08-17 21:32:50

您确定使用的是 POST 吗?对我来说看起来像是一个 GET 请求。


<输入类型=“隐藏”名称=“功能”值=“doitnow”>
<输入类型=“隐藏”名称=“数据”值=“数据”>
// 不要忘记提交按钮

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>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文