2016-08-04 138 views
2

我想用這樣的PHP CURL調用一個vtiger webservice。Vtiger Webservice投擲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); 

但在下面的網址

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

任何人都知道了相同的方案中提到我正在錯誤

error:The requested URL returned error: 406 Not Acceptable 

我只是做所有的進程?

回答

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

     ) 

)