basic-authentication

How do I make a request using HTTP basic authentication with PHP curl?

天大地大妈咪最大 提交于 2019-11-25 21:57:28
问题 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(

Preemptive Basic authentication with Apache HttpClient 4

有些话、适合烂在心里 提交于 2019-11-25 21:25:49
Is there an easier way to setup the http client for preemptive basic authentication than what described here ? In previous version (3.x) it used to be a simple method call (eg, httpClient.getParams().setAuthenticationPreemptive(true) ). The main thing I want to avoid is adding the BasicHttpContext to each method I execute. It's difficult to do this without passing a context through every time, but you can probably do it by using a request interceptor. Here is some code that we use (found from their JIRA, iirc): // Pre-emptive authentication to speed things up BasicHttpContext localContext =