2014-02-07 55 views
0

我有这样的API文档中:如何使PHP脚本来休息

curl -X GET -H ‘Accept: application/xml’ -H ‘Content-Type: application/xml’ \ 
    —user mylogin:mypassword https://subdomain.domain.com/entries 

我需要用PHP来做到这一点。我知道我必须使用CURL。

任何人有一个好主意?

谢谢!

PD:对不起,但我的英语不是很好看。

+0

通过卷曲后发送XML阅读手册是一个好主意。 http://docs.php.net/manual/en/book.curl.php –

回答

0

这是如何在PHP

$username = 'mylogin'; 
$password = 'mypassword'; 

$xml = 'Your xml'; 

curl_setopt($ch, CURLOPT_URL, 'https://subdomain.domain.com/entries'); 
curl_setopt($ch, CURLOPT_USERPWD, $username.':'.$password); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_TIMEOUT, 300); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml')); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); 
$result = curl_exec($ch);