我正在尝试将图像通过PHP和OAuth2上传到App.net。 下面是我正在使用的PHP - 它会导致此错误:
“error_message”:“错误请求:'类型':必需。”
<?php
function sendPost()
{
$postData = array(
'type' => 'com.example.upload',
);
$ch = curl_init('https://alpha-api.app.net/stream/0/files');
$headers = array('Authorization: Bearer '.'0123456789',
'Content-Disposition: form-data; name="content"; filename="http://www.example.com/pics/test.jpg";type=image/jpeg',
'Content-Type: image/jpeg',
);
curl_setopt_array($ch, array(
CURLOPT_POST => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POSTFIELDS => $postData
));
$response = curl_exec($ch);
}
sendPost();
?>
这是来自API documentation:
的cURL示例curl -k -H 'Authorization: BEARER ...' https://alpha-api.app.net/stream/0/files -X POST -F 'type=com.example.test' -F "content=@filename.png;type=image/png" -F "derived_key1=@derived_file1.png;type=image/png" -F "derived_key2=@derived_file2.png;type=image/png;filename=overridden.png"
需要什么类型以及需要更改才能使其正常工作?
非常感谢任何反馈。谢谢。
答案 0 :(得分:0)
您需要执行以下更改
$headers = array(
'Authorization: Bearer '.'0123456789'
);
$postData = array('type' => 'com.example.upload', 'content' => '@/roor/test.png');
当您使用https
时也使用此功能curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true);