简体   繁体   English

使用CURL的XML请求

[英]XML Request Using CURL

I am using curl library to get the XML but getting error of connection with host. 我正在使用curl库获取XML,但与主机的连接出现错误。 Following is my code, I have just removed the credentials. 以下是我的代码,我刚刚删除了凭据。

$url="https://interface.callport.net:8080/P-RVWR-drcm01-cti/call/2142100570";

$curl_post_data = array(
  "query_type" => 'caller_info',
  "dnis" => '8883874944',
);

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 
curl_setopt($ch, CURLOPT_USERPWD, base64_encode('webapi@fastfix:color43t'));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $curl_post_data);

$result = curl_exec($ch);

if(curl_errno($ch))
{
  echo 'Curl error: ' . curl_error($ch);
}
else
{    
  echo $result;
}

curl_close($ch);

It's SSL so this usually fixes the problem. 它是SSL,因此通常可以解决该问题。 cURL does not verify the certificate then. 然后,cURL不会验证证书。

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

[edit] I solved the problems. [编辑]我解决了问题。 First the SSL as described above, then I removed the base64 encoding of the username and password, changed so the data is sent by GET instead of POST and lastly fixed the headers. 首先是如上所述的SSL,然后我删除了用户名和密码的base64编码,进行了更改,因此数据是通过GET而不是POST发送的,最后修复了标头。

$url="https://interface.callport.net:8080/P-RVWR-drcm01-cti/call/2142100570?query_type=caller_info&dnis=8883874944";

$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 
curl_setopt($ch, CURLOPT_USERPWD, 'webapi@fastfix:color43t');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM