请尝试以下代码:
$username='ABC'; $password='XYZ'; $URL='<URL>'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$URL); curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); $result=curl_exec ($ch); $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //get status code curl_close ($ch);
你能试试吗
$ch = curl_init($url); ... curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password); ...
REF: http://php.net/manual/en/function.curl-setopt.php