2015-08-18 120 views
0

這裏是我的功能捲曲語法(佔位符#的到位有效身份證件的的安全性):構建PHP捲曲的語句從捲曲CLI語法

curl -H "Accept: text/xml" https://111222333444555:[email protected]/api/v1/products 

我得到一個有效的XML響應回:

<?xml version="1.0" encoding="UTF-8"?><products><product><created-at>2015-08-06T20:51:19Z</created-at>.... 

這裏是我的PHP語法目前的樣子:

<?php 

//Initialize curl object 
$ch = curl_init(); 

$apikey = "111222333444555"; 
$apisecret = "99999888887777755555"; 
$uri = "https://$apikey:[email protected]/api/v1/products"; 
echo $uri; 
//Define curl options in an array 
$options = array(CURLOPT_URL => $uri, 
       CURLOPT_HEADER => "Accept: text/xml", 
       CURLOPT_HTTPAUTH => CURLAUTH_BASIC, 
       CURLOPT_RETURNTRANSFER => TRUE 
); 

//Set options against curl object 
curl_setopt_array($ch, $options); 

//Assign execution of curl object to a variable 
$data = curl_exec($ch); 

//Close curl object 
curl_close($ch); 

echo ("data is: $data"); 
//Pass results to the SimpleXMLElement function 
$xml = new SimpleXMLElement($data); 

print_r($xml); 

?> 

這似乎$data總是空的,我得到以下錯誤的結果:

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in C:\xampp\htdocs\whd.com\license.php:27 Stack trace: #0 C:\xampp\htdocs\whd.com\license.php(27): SimpleXMLElement->__construct('') #1 {main} thrown in C:\xampp\htdocs\whd.com\license.php on line 27 
+0

如果(FALSE === $數據) 拋出新的異常(curl_error($ CH),curl_errno($ CH)); 告訴我,我的localhost/apache測試服務器上的SSL證書存在問題。猜猜我會嘗試創建一個證書,看看會發生什麼。任何方式在這個? – rbates27

+0

通過設置選項'CURLOPT_SSL_VERIFYPEER => FALSE,CURLOPT_SSL_VERIFYHOST => 0',可以告訴'curl'忽略證書問題。 – axiac

回答

0

我不是堆棧溢出足夠熟悉知道這是否正確的方法幫助,但:

CURLOPT_HEADER => "Accept: text/xml"

應該

CURLOPT_HTTPHEADER => array('Accept: text/xml')