title: RCurl: HTTP Authentication When Site Responds With HTTP 401 Code Without WWW-Authenticate
body: <p>I'm implementing an R wrapper around <a href="http://docs.picloud.com/rest.html">PiCloud's REST API</a> using the <a href="http://www.omegahat.org/RCurl/RCurlJSS.pdf">RCurl</a> package to make HTTP(S) requests to the API server. The API uses Basic HTTP authentication to verify that users have sufficient permissions. The PiCloud documentation gives an example of using the api and authenticating with curl:</p>
  
  <pre><code> $ curl -u 'key:secret_key' https://api.picloud.com/job/?jids=12
  </code></pre>
  
  <p>This works perfectly. Translating this to an equivalent RCurl's command:</p>
  
  <pre><code>getURL("https://api.picloud.com/job/?jids=12", userpwd="key:secret") 
  </code></pre>
  
  <p>Executing this function I receive the following error message:</p>
  
  <pre><code>[1] "{\"error\": {\"msg\": \"No HTTP Authorization information present\", \"code\": 995, \"retry\": false}}"
  </code></pre>
  
  <p>Exploring the issue in more depth I found that the HTTP requests made by the curl command included the Authorization field in the first GET command. </p>
  
  <p>RCurl does not do this. Instead it first sends a GET request without the authorization field set. If it receives a 401 error code AND a response with a WWW-Authenticate field it sends another GET request with the Authorization field. </p>
  
  <p>Although the HTTP spec requires messages that return with a 401 error code to include the WWW-Authenticate field PiCloud API messages do not. Thus when calling <code>getURL</code> even with the userpwd option set RCurl will never send a GET request with the authorization field set. As a result authentication will always fail.</p>
  
  <p>Is there any way to force RCurl to set the Authorization field in the first GET message it sends? If not are there any other R packages that I could look into using?  </p>