неверный JSON при использовании Pivotal API?

0

Я пытаюсь использовать Pivotal API с PHP. Поскольку версия 5 использует JSON вместо XML в предыдущей версии, я попробовал. Вот код:

public function updateStory($id) {
    $update = '{"name":"Here is a test"}';
    $url = "https://www.pivotaltracker.com/services/v5/projects/$this->project/stories/$id";
    $cmd = 'curl -H "X-TrackerToken: ' . $this->token . '" -X PUT -H "Content-Type: application/json" -d \'' . $update . '\'  ' . $url;
    $xml = shell_exec($cmd);

    echo "<pre>";
    echo $cmd;
    var_dump(json_decode($xml, true));
    echo "</pre>";
}

Результат этого кода:

curl -H "X-TrackerToken: TOKEN" -X PUT -H "Content-Type: application/json" -d '{"name":"Here is a test"}' https://www.pivotaltracker.com/services/v5/projects/IDPROJECT/stories/IDSTORY

array (size=5)
    'code' => string 'could_not_parse_body'
    'kind' => string 'error'
    'error' => string 'Cannot parse the JSON-encoded request body.'
    'general_problem' => string 'Couldn't parse the content of the request body.'
    'possible_fix' => string 'The parser returned the following error message:  lexical error: invalid char in json text.
                                       '{name:Here is a test
                     (right here) ------^
'

Когда я выполняю созданную команду выше с помощью Cygwin, она работает. Используя PHP, это не так.

Кто-нибудь знает решение?


На самом деле я уже пробовал это, но он не работает.

Во всяком случае, я пытался использовать curl API в PHP. Зная, что url использует SSL, я следовал этой теме: http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/

Я сгенерировал сертификат, но затем, когда я использую его с PHP curl, у меня есть пустая страница.

Используя Cygwin, у меня есть эта ошибка:

curl --cacert pivotal.crt https://www.pivotaltracker.com/services/v5/projects/1202004/stories/

curl: (60) SSL certificate problem: unable to get local issuer certificate More details here: http://curl.haxx.se/docs/sslcerts.html curl performs SSL certificate verification by default, using a "bundle" of Certificate Authority (CA) public keys (CA certs). If the default bundle file isn't adequate, you can specify an alternate file using the --cacert option. If this HTTPS server uses a certificate signed by a CA represented in the bundle, the certificate verification probably failed due to a problem with the certificate (it might be expired, or the name might not match the domain name in the URL). If you'd like to turn off curl verification of the certificate, use the -k (or --insecure) option.

Любое решение?

Теги:

1 ответ

0

попробуйте var_dump(json_decode(stripslashes($xml), true)); , Вы также можете выполнить некоторую функцию preg, чтобы удалить подозрительные символы, которые, по вашему мнению, могут быть такими, как tab или linebreak. Просто запустите $ xml через пользовательскую функцию, которая выполняет некоторые проверки на json_decode перед переходом на json_decode

Ещё вопросы

Сообщество Overcoder
Наверх
Меню