我正在将Badgeville与我的PHP5.3、curl 7.22应用程序集成。
BV的API文档都使用命令行curl调用作为示例。当我运行这些示例时,它们工作得很好。
当我试图对PHP类做同样的事情时,我总是从BV服务器得到500个错误。
我尝试使用Chrome中的Advanced客户端扩展来实现同步功能。
PHP Curl示例:
$ch = curl_init('http://sandbox.v2.badgeville.com/api/berlin/[private_api_key]/users.json');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
if($this->getRequestType() == 'POST')
{
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,
array(
'user[name]' => 'Generic+Username',
'user[email]' => 'johndoe%40domainname.com'
);
);
}
$response = curl_exec($ch);
Rest客户端示例:
网址:[键]/users.json 张贴无标题有效载荷: username=Generic+Username&useremail=johndoe%40domainname.com
我已经手动创建了命令行curl调用,并使用shell_exec()
运行了该命令行,但我确实不希望这样做。
在我的研究中,我发现了一个Drupal,所有的模块调用都是通过fsockopen()
调用完成的。
是否有什么方法可以成功地使用PHP类进行Badgeville调用?
发布于 2013-03-05 19:20:48
结果显示,当有设置头的卷曲请求时,Badgeville有一个500错误。
返回代码时出错:
$ch = curl_init('http://sandbox.v2.badgeville.com/api/berlin/[private_api_key]/users.json');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
if($this->getRequestType() == 'POST')
{
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,
array(
'user[name]' => 'Generic+Username',
'user[email]' => 'johndoe%40domainname.com'
);
);
}
$response = curl_exec($ch);
正常运作的代码:
$ch = curl_init('http://sandbox.v2.badgeville.com/api/berlin/[private_api_key]/users.json');
//curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
if($this->getRequestType() == 'POST')
{
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,
array(
'user[name]' => 'Generic+Username',
'user[email]' => 'johndoe%40domainname.com'
);
);
}
$response = curl_exec($ch);
SMH
https://stackoverflow.com/questions/15216206
复制相似问题