开发者

curl php authentication not working

i know there are alot of questions out there but none solved my problem

i have to authenticate with uername and password and used curl as

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "/example.domain/tmp");
curl_setopt($ch, CURLOPT_USERPWD, "user:pwd");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, 1);
$ou开发者_如何学JAVAtput = curl_exec($ch);
curl_close($ch);

but every time it just returns false.

I'm pretty new to using cURL so I could be making some beginner mistakes, but I'm confused as to why this isn't working at all.

Any help would be greatly appreciated!


you are missing return transfer which is set to 1

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

write it before your CURLOPT_USERPWD i.e

curl_setopt($ch, CURLOPT_USERPWD, "user:pwd");

then it might work. see if it work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜