CURL适用于终端但在PHP代码中显示错误?

时间:2015-11-05 12:35:24

标签: php curl

当我使用终端使用CURL发布图像时,它工作正常,但是当我在PHP代码中对其进行转换时,它会抛出error 400 Bad Request

使用终端

的CURL代码
curl -H "Authorization: Bearer ${access_token}" \
     -H "Content-Type: image/jpeg" \
     -i \
     -X POST \
     --data-binary @my_image.jpg \
     https://example.com/objects/v1/files

PHP文件中的CURL代码

$headers = array(
   'Content-Type: image/jpeg',
   'Authorization: Bearer ' . $accessToken,    
);
$binary = 'my_image.jpg';
$ch = curl_init('https://example.com/objects/v1/files');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, '@'.$binary);

0 个答案:

没有答案