【发布时间】:2017-01-12 05:26:45
【问题描述】:
我正在使用 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;
}
【问题讨论】:
-
请澄清您的具体问题或添加其他详细信息以准确突出您的需要。正如目前所写的那样,很难准确地说出你在问什么。请参阅How to Ask 页面以获得澄清此问题的帮助。
-
谢谢。现在我已经编辑了帖子。
-
-T, --upload-file <file> This transfers the specified local file to the remote URL. If there is no file part in the specified URL, Curl will append the local file name. NOTE that you must use a trailing / on the last directory to really prove to Curl that there is no file name or curl will think that your last directory name is the remote file name to use. That will most likely cause the upload operation to fail -
您的标头
Expect也没有价值,因此无效。 Apache 比热锅更快地丢弃无效标头。我不确定你为什么不使用 php cURL 模块。它更容易使用。如果要上传文件,需要使用正确的Content-Typeheader。 -
整个过程由网络服务器(Apache 或 Nginx)w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.2.3 处理
标签: php curl http-headers