我想为Cloudant数据库定义不同的搜索字符串。但是我的卷曲功能存在问题。你看错了吗?
function get_results($url, $bookmark = NULL, $results = array()){
$username = 'name';
$password = 'pw';
$url = $bookmark !== NULL ? $url."&bookmark=$bookmark" : $url;
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$r = curl_exec($ch);
curl_close($ch);
$response = json_decode($r);
if(count($response->rows) === 200){
foreach($response->rows as $row){
$results[] = $row->doc;
}
return get_results($url, $response->bookmark, $results);
} else {
foreach($response->rows as $row){
$results[] = $row->doc;
}
return $results;
}
}
我接受了这个警告/通知:
Notice: Trying to get property of non-object in C:\xampp\... on line 62
Notice: Trying to get property of non-object in C:\xampp\... on line 68
Warning: Invalid argument supplied for foreach() in C:\xampp\... on line 68
第62行是:if(count($ response-> rows)=== 200){
第68行是:foreach($ response->行为$ row){
谢谢!
答案 0 :(得分:0)
在curl中使用以下标题选项,将返回json对象:
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
因为默认接受类型是Text / Plain,所以它会返回你解析的sting。通过设置上面的标题,您将收到json对象。
答案 1 :(得分:0)
curl.cainfo
并重启服务器
或者只使用CURLOPT_CAINFO
选项进行配置。永久设置在php.ini中:
curl.cainfo="/path/to/cacert.pem"
暂时在PHP代码中设置:
curl_setopt($ch, CURLOPT_CAINFO, '/path/to/cacert.pem');
答案 2 :(得分:-1)
我明白了!问题是ssl证书。我用
禁用了它curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
现在我收到了回复!