我正在使用 PHP Curl 类,http://query7.com/php-curl并且需要从具有基本身份验证的第三方服务提供商获取内容。
我不知道如何将我的身份验证详细信息(即用户名和密码)传递给上面指定的 curl 类。
我正在使用 PHP Curl 类,http://query7.com/php-curl并且需要从具有基本身份验证的第三方服务提供商获取内容。
我不知道如何将我的身份验证详细信息(即用户名和密码)传递给上面指定的 curl 类。
将最后一行添加到您的选项数组中:
public $options = array(
    CURLOPT_RETURNTRANSFER => true,     // return the web page
    CURLOPT_HEADER         => false,    // don't return the headers
    CURLOPT_FOLLOWLOCATION => true,     // follow redirects
    CURLOPT_USERAGENT      => "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)", // set a normal looking useragent
    CURLOPT_AUTOREFERER    => true,     // set referer on redirect
    CURLOPT_CONNECTTIMEOUT => 120,      // timeout
    CURLOPT_TIMEOUT        => 120,      // timeout
    CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects
    CURLOPT_USERPWD        => $username . ":" . $password // Basic auth
);
通常,您可以像这样将用户名和密码传递给域:
http://username:password@query7.com/php-curl