我试图像这样使用PHP CURL调用vtiger webservice。
$selectQuery = urlencode("SELECT title,firstname,lastname FROM Contacts;");
$curl = curl_init($data['url'].'/webservice.php?operation=query&sessionName='.$this->sessionName.'&query='.$selectQuery);
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept: application/json'));
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0");
curl_setopt($curl, CURLINFO_HEADER_OUT, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
$query = curl_exec($curl);
//$query = json_decode($query);
print_r($query);
但我收到了错误
error:The requested URL returned error: 406 Not Acceptable
我正在执行以下网址
中提到的所有流程有人知道相同的解决方案吗?
答案 0 :(得分:-1)
Hi Root ingenious请尝试
我的代码
$endURL = 'http://192.168.192.140/vtigercrm71'; //use ur url
$userName = 'admin'; //use ur username
$userAccessKey = 'h3fNwMr0Nc2hNQOL'; //use ur useraccesskey
$url = $endURL . '/webservice.php?operation=getchallenge&username=' . $userName;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, 0);
$output = curl_exec($ch);
curl_close($ch);
$res = json_decode($output);
$challengeToken = $res->result->token;
$generatedKey = md5($challengeToken . $userAccessKey);
$params = array(
"operation" => 'login',
"username" => $userName,
"accessKey" => $generatedKey,
);
$postData = '';
foreach ($params as $k => $v) {
$postData .= $k . '=' . $v . '&';
}
$postData = rtrim($postData, '&');
$url = $endURL . '/webservice.php';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, count($postData));
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$output = curl_exec($ch);
curl_close($ch);
$res = json_decode($output);
$sessionName = $res->result->sessionName;
$userId = $res->result->userId;
$domain_name = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'];
$selectQuery = urlencode("SELECT title,firstname,lastname FROM Contacts;");
$url = $endURL . '/webservice.php?operation=query&query=' . $selectQuery . '&sessionName=' . $sessionName;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, 0);
$output = curl_exec($ch);
curl_close($ch);
$res = json_decode($output);
echo "<pre>";
print_r($res);
exit;
结果
stdClass Object
(
[success] => 1
[result] => Array
(
[0] => stdClass Object
(
[title] =>
[firstname] => asdfas
[lastname] => dfdsafdsf
[id] => 12x3
)
)
)