我正在尝试将 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'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) ------^
'
当我使用 Cygwin 执行上面创建的命令时,它可以工作。使用 PHP,它不会。
有谁知道解决方案?
其实我已经试过了,但它不起作用。
无论如何,我尝试在 PHP 中使用 curl API。知道 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's verification of the certificate, use
the -k (or --insecure) option.
有什么解决办法??