我正在编写一个 PHP 应用程序,它必须将 pdf 文件上传到我的企业 Box.com 帐户。
我收到 400 错误(请求中的输入参数无效),但我认为一切都是正确的。
function upload( $doc ) {
if ( ! $this->access() )
$this->getAccess();
if ( ! is_readable($doc) )
return false;
$this->curl->clear();
// $this->curl->setUpload( true );
$this->curl->setMethod( 'POST' );
$this->curl->setHeaders( $this->_header() );
$this->curl->setValues( array(
'parent_id' => 0,
'filename' => '@'.$doc
));
$this->curl->exec( 'https://upload.box.com/api/2.0/files/content' );
echo '<pre>'; print_r($this->curl->getHeaders()); echo '</pre>';
echo '<pre>'; print_r($this->curl->getValues()); echo '</pre>';
$response = $this->curl->getResult(true);
echo "<pre>"; print_r($response); echo "</pre>"; exit;
}
结果:
POST /api/2.0/files/content HTTP/1.1
User-Agent: User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:22.0) Gecko/20100101 Firefox/22.0
Host: upload.box.com
Accept: */*
Authorization: Bearer .....
Content-Length: 89
Content-Type: application/x-www-form-urlencoded
Array
(
[parent_id] => 0
[filename] => @/Applications/XAMPP/xamppfiles/htdocs/MyFile.pdf
)
stdClass Object
(
[type] => error
[status] => 400
[code] => invalid_request_parameters
[help_url] => http://developers.box.com/docs/#errors
[message] => Invalid input parameters in request
[request_id] => ......
)
当我取消注释用于制作 cURL 上传文件的行时,方法从 POST 更改为 PUT,然后我收到错误 405 Method Not Allowed。
根据此处的 API 文档http://developers.box.com/docs/#files-upload-a-file我正在正确发送所有内容。