phpcurl无法放入Amazon s3

时间:2019-04-03 17:09:33

标签: php curl amazon-s3 php-curl

如果我使用curl将其放入Amazon S3,则请求和响应工作正常。使用phpcurl我收到一个SignatureDoesNotMatch错误。但是我认为这两种情况下的签名都是相同的。下面我有curl请求和php请求。

卷曲请求

PUT long_amazon_url_here
Host: s3.amazonaws.com
User-Agent: curl/7.58.0
Accept: */*
Content-Type: application/pdf
x-amz-server-side-encryption: AES256
Content-Length: 655786
Expect: 100-continue

php curl请求

PUT long_amazon_url_here
Accept: */*
x-amz-server-side-encryption: AES256
Content-Length: 656028
Content-Type: application/pdf; boundary=------------------------53e1e1c959bffe27
Expect: 100-continue

卷曲代码为:

curl --verbose -X PUT -T file.pdf -H "Content-Type: application/pdf" -H "x-amz-server-side-encryption: AES256" "long_amazon_url_here"

php代码如下:

$header = array(
"x-amz-server-side-encryption: AES256",
"Content-Type: application/pdf");

$url = long_amazon_url_here 
$cFile = curl_file_create($fullPath_to_file);
$post = array('file_contents'=> $cFile);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$response = curl_exec($ch);

有人知道我可以进行哪些更改以使phpcurl版本正常工作吗?

0 个答案:

没有答案