How to form PHP curl request for the following command line?

ぃ、小莉子 提交于 2020-01-15 07:40:28

问题


Can someone help me to form this commndline request in PHP ?

$ curl -u [USER:PASSWORD] https://subs.pinpayments.com/api/v4/meresheep/subscribers/7388.xml

I have tried the following and getting only 'false' returned...

 // Query the user to pin payments for the details...
 $curl_url = "https://subs.pinpayments.com/api/v4/xyz-site/subscribers/32.xml";

 //open connection
 $ch = curl_init();

 //set the url, number of POST vars, POST data
 curl_setopt($ch, CURLOPT_URL, $url);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
 curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: -u [USER:PASSWORD]'));

 //execute post
 $result = curl_exec($ch);
 curl_close($ch);

回答1:


You need to change the CURLOPT_HTTPHEADER line:

curl_setopt($data, CURLOPT_HTTPHEADER, array(
    'Authorization: Basic ' . base64_encode('username:password')
));


来源:https://stackoverflow.com/questions/21848666/how-to-form-php-curl-request-for-the-following-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!