How do I make a request using HTTP basic authentication with PHP curl?
问题 I\'m building a REST web service client in PHP and at the moment I\'m using curl to make requests to the service. How do I use curl to make authenticated (http basic) requests? Do I have to add the headers myself? 回答1: You want this: curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password); Zend has a REST client and zend_http_client and I'm sure PEAR has some sort of wrapper. But its easy enough to do on your own. So the entire request might look something like this: $ch = curl_init(