title: Get site content over SSL with httr in R
body: <p>I'm trying to fetch a JSON array from my server using the HTTP POST method in R. </p>
  
  <p>I've tried using both the <code>POST</code>function from <code>httr</code>and the <code>getURL</code>function from <code>RCurl</code> but both return errors.</p>
  
  <pre><code>cafile &lt;- system.file("CurlSSL", "cacert.pem", package = "RCurl")
  url    &lt;- "https://example.com/query/getData.php"
  
  POST(url,body=NULL)
  POST(url,body=NULL,config(cainfo=cafile))
  
  getURL(url)
  getURL(url,cainfo=cafile)
  </code></pre>
  
  <p>The error given by the <code>POST</code> function is (for both calls):</p>
  
  <pre><code>Error in curl::curl_fetch_memory(url, handle = handle) : 
    SSL peer certificate or SSH remote key was not OK
  </code></pre>
  
  <p>The error given by the <code>getURL</code> function is (without <code>config(cainfo=cafile)</code>):</p>
  
  <pre><code>* Hostname was NOT found in DNS cache
  *   Trying 162.xxx.xxx.xxx...
  * connect to 162.xxx.xxx.xxx port 443 failed: Connection refused
  *   Trying 130.yyy.yyy.yyy...
  * Connected to example.com (130.yyy.yyy.yyy) port 443 (#0)
  * found 175 certificates in /etc/ssl/certs/ca-certificates.crt
  * gnutls_handshake() warning: The server name sent was not recognized
  * failed to get server cert
  * Closing connection 0
  Error in function (type, msg, asError = TRUE)  : 
    gnutls_handshake() warning: The server name sent was not recognized
  </code></pre>
  
  <p>I'm suspecting this has something to do with R since running:</p>
  
  <pre><code>curl 'https://example.com/query/getData.php'
  </code></pre>
  
  <p>from the command line return the expected result.</p>
  
  <p>The server is a apache2 server with COMODO SSL certificate.
  In  <code>/etc/apache2/sites-enabled/000-default.conf</code> the server name is set to </p>
  
  <pre><code>ServerName www.example.com  
  </code></pre>
  
  <p>Any help would be most apreciated</p>