Ошибка при отправке данных JSON с помощью Curl — «неверный символ в тексте json»

Я экспериментирую с API Basecamp, пытаясь создать проект.

Я использую следующий код:

    #CONTENT-TYPE HEADER
$helloHeader = "User-Agent: $appName ($appContact)";

#URL
$url= $baseUrl.'/projects.json';

#JSON DATA
$data = array
(
'nome' => 'project xpto'
);

$data_aux = json_encode($data);

$data_string = 'json=' . $data_aux . '&';

#INITIALIZE
$ch = curl_init($url);

#standard
curl_setopt($ch, CURLOPT_USERPWD, $credentials);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);

#OBTAIN DATA
//curl_setopt($ch, CURLOPT_HTTPGET, true);

#SEND DATA
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"User-Agent: " . $appName . "(" . $appContact . ")")
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);

$response = curl_exec($ch);

#ERRORS?
$errno = curl_errno($ch);
$error = curl_error($ch);

#CLOSE
curl_close($ch);

И у меня появляется следующая ошибка:

lexical error: invalid char in json text.
json={"nome":"project xpto"}&
(right here) ------^

Есть идеи, что я делаю не так? Я пытался изменить массив несколькими способами, но я не могу понять эту ошибку!

0

Решение

Задача ещё не решена.

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

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

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