如何在PHP中处理HTTP Expect标头

用户名

我正在使用curl命令通过POST请求发送文件。我没有使用PHP curl库。但是,curl命令太客气了,会发送Expect标头。我应该如何在服务器端处理它?我知道服务器必须返回100个继续响应,但是如何继续接收文件?$ _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;
}
miken32

在服务器端,这应由您的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使用HTTP 1.1标头,因此将请求发送为HTTP 1.0应该可以解决此问题。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章