我知道外面有很多问题,但没有一个能解决我的问题
我必须用用户名和密码进行身份验证,并使用curl作为
$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);
$output = curl_exec($ch);
curl_close($ch);
但是每次都返回false
我是一个很新的使用cURL,所以我可能会犯一些初学者的错误,但我很困惑,为什么这是不工作。
任何帮助都将非常感激!
您错过了设置为1的返回传输
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
写在CURLOPT_USERPWD之前,即
curl_setopt($ch, CURLOPT_USERPWD, "user:pwd");
则可能有效。