我使用curl命令通过POST请求发送文件。我没有使用PHP curl库。但是,curl命令太客气了,会发送一个Expect报头。我应该如何在服务器端处理它?我知道服务器必须返回一个100-continue响应,但它如何继续接收文件?$_FILES数组始终为空。
这是我发送给服务器的内容:
/usr/bin/curl -sS -X POST -T "/tmp/phpuPfIDd" http://localhost/stats/rgateway/index.php/data 2>&1服务器端代码应该是这样的:
<?php
session_start();
switch($_SERVER['REQUEST_METHOD']) {
case 'GET':
# Do something if it is a GET request
break;
case 'POST':
$headers = apache_request_headers();
if (array_key_exists('Expect', $headers)) {
# What should I do here in order to receive uploaded the file?
}
break;
}发布于 2016-09-05 07:27:41
在服务器端,这应该由你的web服务器来处理,而不需要PHP去担心这些底层的事情。
来自man curl的相关部分
-0, --http1.0
(HTTP) Tells curl to use HTTP version 1.0 instead of using its
internally preferred: HTTP 1.1.
--expect100-timeout <seconds>
(HTTP) Maximum time in seconds that you allow curl to wait for a
100-continue response when curl emits an Expects: 100-continue
header in its request. By default curl will wait one second. This
option accepts decimal values! When curl stops waiting, it will
continue as if the response has been received.
(Added in 7.47.0)因此,如果你有一个足够新的版本,看起来cURL将“继续,就像已经收到响应一样”。如果您没有足够新的版本,Expect是一个HTTP1.1报头,所以将请求作为HTTP1.0发送应该可以解决问题。
https://stackoverflow.com/questions/39320470
复制相似问题