Encoding password field for HTTP Basic Auth
<p>I using PHP cURL to communicate with a Rest API. Most of the functionality is carried out using X-Ephemeral-Tokens, but unfortunately they don't allow delete permissions to be given through these, so I am having to implement a function to delete through HTTP Basic Authentication.</p>

<p>The trouble I'm having is that the password for the testing account is a random string, including multiple special characters (double quotation marks being some of them). I got the request working using the normal cURL binary by surrounding the <code>username:password</code> combination in single quotes (i.e. <code>'</code>) but I'm not sure how to convert this to PHP. The relevant snippet is below.</p>

<pre><code>$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Accept: application/json",
                                              "Content-Type: application/json"));
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, $uname . ":" . $pass);
curl_setopt($curl, CURLOPT_URL, "https://cloud.ravellosystems.com/api/v1/applications/" . $appid);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
$result = curl_exec($curl);
</code></pre>

<p>I've tried various combinations of quotation marks and URL encoding but I still get a response code which indicates the authentication isn't working right.</p>

<p>This is and exmaple HTTP request based on what the API documentation shows for using normal cURL (amended slightly)</p>

<pre><code>curl -v -X DELETE -H "Content-Type: application/json" -H "Accept: application/json" --user ravello@ravello.com:password https://cloud.ravellosystems.com/api/v1/applications/414244
</code></pre>

<p>Any suggestions on how to get around this greatly appreciated.</p>