php - 谷歌云存储 : Upload Object is returning HTTP/1. 1 100 继续

标签 php http curl google-cloud-storage

我注意到,自 2013 年 7 月 29 日起,GCS Web 服务开始返回“HTTP/1.1 100 Continue”,而不是通常的“HTTP/1.1 200 OK”(后面是有关服务器的一些元数据)。

这是在我执行 PUT 对象时看到的。

我的问题是,如何解决这个问题?我只需重新发送请求吗?我是否将请求重定向到另一个位置?


这是我的请求:

    $headers = array('Host: '.$bucket.'.commondatastorage.googleapis.com',
                    'Date: '.$timestamp, $version_header, 'Content-Type: text/plain',
                    $project_header, 'Content-Length: '.filesize($objectPath),
                    'Authorization: OAuth '.$accessToken);

    $c   = curl_init();
    curl_setopt($c, CURLOPT_URL, $url);
    curl_setopt($c, CURLOPT_PUT, 1);
    curl_setopt($c, CURLOPT_INFILE, $fp); 
    curl_setopt($c, CURLOPT_INFILESIZE, filesize($objectPath)); 
    curl_setopt($c, CURLOPT_HEADER, 1);
    curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($c, CURLOPT_CUSTOMREQUEST, "PUT");
    curl_setopt($c, CURLOPT_TIMEOUT, 60); //timeout in 60s
    curl_setopt($c, CURLOPT_HTTPHEADER, $headers);
    $response = curl_exec($c);

最佳答案

这是 HTTP 1.1 的一项功能;

基本上,您的客户端仅发送带有额外行的 header

Expect: 100-continue

...并等待发布正文几百毫秒。如果超时或服务器返回 100 Continue 响应,客户端将继续上传,如果返回 417 Expectation Failed,则上传将中止。

这允许服务器在上传之前检查是否接受请求。例如,如果文件大小大于 Google Cloud Storage 的剩余配额,则在被拒绝之前上传它是没有用的。

上传完成后,您将像往常一样收到额外的 200 OK 响应。

编辑:

我发现您正在运行 PHP。有关 PHP/Curl 的更多信息,请参阅 this question .

关于php - 谷歌云存储 : Upload Object is returning HTTP/1. 1 100 继续,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18001941/

相关文章:

azure - Windows 命令提示符curl POST 运行 Azure DevOps 管道

php - 在 WooCommerce 订阅续订订单中设置送货方式

php - echo 逐行执行命令的结果

php - 有没有办法在插入时使用 sql 查询或 sql 触发器来执行 PHP 页面或 URL?

php - 在 android 应用程序和 php 服务器中使用 http get/post 请求时出现文本编码错误?

json - Golang Chi 路由器不呈现响应负载 JSON

php - 如何将内部标签定位在不同的位置?

python - 我只想下载此 URL...但它给我一个错误! ...unicode..(Python)

java - 如何从 URL 下载 .jar 文件

curl - Paypal 沙箱异常 "Unable to communicate with the PayPal gateway"Magento