2016-08-04 19 views
2

このようにPHP CURLを使用してvtiger Webサービスを呼び出そうとしています。Vtiger Webservice throw 406エラー

$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 

を取得しています以下のURLで述べたように私は誰もが同じのためのソリューションを知っている

http://community.vtiger.com/help/vtigercrm/developers/third-party-app-integration.html#list-types-operation

すべてのプロセスをやっていますか?

答えて

-1

こんにちはルート独創的な

私のコード

$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 
       ) 

     ) 

) 
を試してみてください