我正在尝试发一个 curl 帖子来上传我的应用程序,但我不知道我做错了什么,但我在响应中不断收到 500 错误,我不知道该怎么办了......
// basic settings for your Zendesk
$userName = 'xxxxx@xxxx.com/token';
$apiKey = 'xkalkjsdXASJKDlasaknfkajsfASASASD';
// upload file info
$fileName = 'v5.0.zip';
$filePath = 'path/to/file/v5.0.zip';
$url = 'https://mysubdomain.zendesk.com/api/v2/apps/uploads.json';
$file = fopen($filePath, "r");
$size = filesize($filePath);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, $userName.":".$apiKey);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/binary'));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1);
curl_setopt($ch, CURLOPT_HEADER, 0); // DO NOT RETURN HTTP HEADERS
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1); // RETURN THE CONTENTS OF THE CALL
curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, array($fileName => "@".$filePath));
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
$output = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
fclose($file);
curl_close($ch);
我已经尝试进入命令行,并且效果很好:
curl https://subdomain.zendesk.com/api/v2/apps/uploads.json \
-F uploaded_data=@/path/to/file/v5.0.zip -X POST \
-u "user/token:tokenpassword"
问题是,有没有人知道我做错了什么?我真的很绝望!
谢谢你们,
丹尼尔