title: How to solve x509: certificate has expired or is not yet valid when doing http requests
body: <p>I have a web server that gets it's certs from <code>golang.org/x/crypto/acme/autocert</code><p>
  I run it on a VM.<p>
  Relevante code:</p>
  <pre><code>cache := autocert.DirCache(&quot;cert&quot;)
  
  certManager := autocert.Manager{
      Prompt:     autocert.AcceptTOS,
      HostPolicy: autocert.HostWhitelist(common.ConfHost.GetString(), &quot;www.&quot;+common.ConfHost.GetString()),
      Email:      common.ConfEmail.GetString(),
      Cache:      cache,
  }
  </code></pre>
  <p>This is what I'm using for HTTP Requests: <code>resp, err := http.DefaultClient.Get(url)</code><p>
  When I try to fetch from a specific API, I get this error: <code>x509: certificate has expired or is not yet valid current time 2020-12-28T17:29:37Z is after 2020-12-26T08:22:28Z</code><p>
  But it only happens to that specific API. I've tried a few others and they all worked.<p>
  The code was working until the 26th of December, when the certificate expired.<p>
  On the other hand, I wrote a <code>main.go</code> to test without all the certificates that I have to use on my webserver just to test. When I run the code on my local machine I get the response from the API without any issues.<p>
  This is the <code>main.go</code> file: <a href="https://play.golang.org/p/-EB9DIjJYQO" rel="nofollow noreferrer">https://play.golang.org/p/-EB9DIjJYQO</a><p>
  How can I fix this issue?</p>