Php curl basic authentication in accordance with RFC2617

I want to send data to url using basic authentication in accordance with RFC2617

$header = base64_encode("testindia01@test.com:india123");

 curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: text/plain', 'Authorization: Basic '.$header));

What else do I need to do here, I pass ': shared username and password using base64 encoding?

I get a 401 response , which is unauthorized, where, when my username and password are valid, I can log in using them.

thank

+1
source share
1 answer

Instead of manually entering the authentication header, use CURL_USERPWDand CURLOPT_HTTPAUTH=>CURLAUTH_BASIC.

http://php.net/manual/en/function.curl-setopt.php#98164

+2
source

All Articles