2014-11-07 2 views
0

PHP에서 Pivotal API를 사용하려고합니다. 이전 버전에서는 버전 5가 XML 대신 JSON을 사용하기 때문에 시도했습니다.Pivotal API를 사용하는 JSON이 잘못 되었나요?

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's 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) ------^ 
' 

I가 시그윈를 사용하여 상기 생성 된 명령을 실행하면, 여기에 작동 코드이다. PHP를 사용하면 그렇지 않습니다.

누구나 해결책을 알고 있습니까?


실제로 이미 시도했지만 작동하지 않습니다.

어쨌든 PHP에서 curl API를 사용하려고했습니다. SSL을 사용하는 URL을 알면 다음 스레드를 따라갔습니다. http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/

인증서를 생성했지만 PHP 컬링과 함께 사용할 때 빈 페이지가 나타납니다.

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's verification of the certificate, use the -k (or --insecure) option.

모든 솔루션을?

답변

0

시도 var_dump(json_decode(stripslashes($xml), true));. 탭 또는 줄 바꿈과 같은 것으로 의심되는 용의자를 제거하기 위해 일부 사전 기능을 수행 할 수도 있습니다. json_decode

로 전달하기 전에 몇 가지 온 전성 검사를 수행하는 사용자 지정 함수를 통해 $ xml을 실행하면됩니다.