Encoding password field for HTTP Basic Auth Encoding password field for HTTP Basic Auth curl curl

Encoding password field for HTTP Basic Auth


Ok so if anyone else has this issue, I've found a solution.

Basically you can see in my code above that I was trying to use the cURL PHP methods to set options for CURLOPT_USERPWD and CURLOPT_HTTPAUTH. However somewhere in this the special characters in the password were causing issues with the parsing and I think only a section of it was actually being taken by the server.

However, all that these options do basically is set an HTTP header, as can be seen in @mpyw screenshots. This is the Authorization header, which is in the format below:

`Authorization: Basic [base64 encoded username:password]`

So I got rid of these options and did it manually, by base64 encoding my username:password string myself and then adding a header.

$auth = base64_encode($uname . ":" . $pass);curl_setopt($curl, CURLOPT_HTTPHEADER, array("Authorization: Basic $auth",                                              "Accept: application/json",                                              "Content-Type: application/json"));

Now it all works fine! Thanks to the guys who posted answers - both of you contributed to me coming up with the workaround.


I compared two ways, enabling verbose outputs.

enter image description hereenter image description here

Emitted headers are the same, except that the PHP does not contain User-Agent header. Does the API require User-Agent header?


Edit

Password that contains '

enter image description hereenter image description here

Password that contains "

enter image description hereenter image description here


I believe that you have to base64_encode the username and password. Try this:

curl_setopt($curl, CURLOPT_USERPWD, base64_encode($uname . ":" . $pass));