Пытаюсь подключить endpoint загрузки файла на сервер
https://unicheck.com/plagiarism-api-documentation#...
Авторизация проходит успешно, и вот те данные которые я отправляю (токен изменил)
[
"POST",
"https://api.unicheck.com/files",
{
"Content-Type": "multipart/form-data",
"Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjcwOTIyNCJ9.eyJhdWQiOiI5MmM1NzgxMDJlMGExMjEyZmU3YSIsImp0aSI6IjcwOTIyNCIsImlhdCI6MTU1NjI3MTQ5MSwibmJmIjoxNTU2MjcxNDkxLCJleHAiOjE1NTg4NjM0OTEsInN1YiI6IjIxOTYxOSIsInNjb3BlcyI6W119.PAblUxv92aXCD0WyaKEvaeG_7HiwqrFQ4Gya7_AFiJgEW3nN5xhICu6r-XyVw8C4WTHKYV8d11VNMKfYPHawasdfaERAGaeragdHO9E4lPdHkWM516nN9LtHk0Iwc7kalKluQfn17h7GFkHPjzKHEz20FENZJqzB2AGzXdo",
"Accept": "application/vnd.api+json"
},
{
"file": "/private/var/folders/dt/sj5sm2ps0t58g8fvrx1p2sl40000gn/T/phpGhMxLp/Doc.docx"
}
]
Получаю при этом:{
"jsonapi": {
"version": "1.0"
},
"errors": [
{
"status": 403,
"title": "Forbidden"
}
]
}
Прилагаю исходники:public function check_file(Request $request, RequestApi $make_request)
{
$config = [
'url' => 'https://api.unicheck.com',
'grant_type' => 'client_credentials',
'client_secret' => 'my_secret',
'client_id' => 'my_id',
'token' => '',
];
$response = json_decode($make_request->send(
'GET',
$config['url'].'/oauth/access-token',
['Content-Type' => 'application/x-www-form-urlencoded'],
[
'grant_type' => $config['grant_type'],
'client_secret' => $config['client_secret'],
'client_id' => $config['client_id'],
]
));
$config['token'] = $response->token_type.' '.$response->access_token;
$response = json_decode($make_request->send(
'POST',
$config['url'].'/files',
[
'Content-Type' => 'multipart/form-data',
'Authorization' => $config['token'],
'Accept' => 'application/vnd.api+json',
],
['file' => $_FILES['file']['tmp_name'].'/'.$_FILES['file']['name']]
));
return new JsonResponse($response);
}
namespace App\Service;
class RequestApi
{
static function send($method, $url, $headers = [], $data = false)
{
$curl = curl_init();
switch ($method)
{
case "POST":
curl_setopt($curl, CURLOPT_POST, 1);
break;
case "PUT":
curl_setopt($curl, CURLOPT_PUT, 1);
break;
}
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLINFO_HEADER_OUT, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
if ($data) {
curl_setopt($curl, CURLOPT_POSTFIELDS, (is_array($data)) ? http_build_query($data) : $data);
}
$result = curl_exec($curl);
var_dump(curl_getinfo($curl));
curl_close($curl);
return $result;
}
}
Так же в запросах почему-то не подключаются заголовки: pr 26 13:02:05 |DEBUG| PHP POST /files HTTP/1.1
pr 26 13:02:05 |DEBUG| PHP Host: api.unicheck.com
pr 26 13:02:05 |DEBUG| PHP Accept: */*
pr 26 13:02:05 |DEBUG| PHP Content-Length: 96
pr 26 13:02:05 |DEBUG| PHP Content-Type: application/x-www-form-urlencoded
pr 26 13:02:05 |DEBUG| PHP
Apr 26 13:02:05 |DEBUG| PHP * upload completely sent off: 96 out of 96 bytes