HTTP POST 错误 414
我使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果数据以 URL 结尾,则您不会以 POST 方式发送请求。使用 POST 时,请求看起来像这样(不完整):
但是 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):
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.
有多种方法可以做到这一点,具体取决于您有权访问接收请求的 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 脚本的包装器:
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
asPOST
instead ofGET
. 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:
您需要发出 POST 请求而不是 GET 请求。
You need to make a POST request instead of a GET request.
您确定使用的是 POST 吗?对我来说看起来像是一个 GET 请求。
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>