当我使用终端使用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);