Диалог IBM — Curl — PHP Laravel

У Уотсона есть следующий код:

 curl -u "{username}":"{password}"-X POST
--form file=@template.xml
--form name=templateName
"https://gateway.watsonplatform.net/dialog/api/v1/dialogs"

И я имею:

$ch = curl_init();
$data['name'] = $this->post['name'].";type:form";
$data['file'] = $this->getCurlValue($this->post['file'], $this->post['nombre']);

curl_setopt($ch, CURLOPT_URL, $this->url.$this->metodo);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_USERPWD, "{$this->user}:{$this->pass}");

if(count($this->post) > 0){
//curl_setopt($ch, CURLOPT_PUT, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
$output = curl_exec($ch);
curl_close($ch);
json_decode($output);

$ this-> сообщение имеет …

$data = Request::only('name', 'file');

И я получаю только ответ: {}

Что мне не хватает?

Спасибо всем! … В первый раз попробуйте отправить файл загрузки с помощью curl: c

1

Решение

Это было проще, чем я предполагал.

Хранить:

$data = Request::only('name', 'file');

$nombre = time().".".Request::file('file')->getClientOriginalExtension();
Request::file('file')->move(base_path() . '/public/dialogos/', $nombre);

$data['path'] = base_path() . '/public/dialogos/'.$nombre;
$data['file'] = $_FILES['file'];

Скручивание:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->url.$this->metodo);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_USERPWD, "{$this->user}:{$this->pass}");

if(count($this->post) > 0){
$datos['name'] = $this->post['name'];
$datos['file'] = $this->getCurlValue($this->post['file'], $this->post['path']);
curl_setopt($ch, CURLOPT_POSTFIELDS, $datos);
}
$output = curl_exec($ch);
curl_close($ch);
return json_decode($output);

getCurlValue ($ file, $ path);

if (function_exists('curl_file_create')) {
return curl_file_create($path, $file['type'], $file['name']);
}
$value = "@{$path};filename=" . $file['name'];
$value .= ';type=' . $file['type'];

return $value;

Глупый MSG, который сказал, что мне нужны методы PUT или DELETE … ха-ха

0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector