title: Access HTTPS via HTTP proxy with basic authentication
body: <p>I am trying to make a <code>GET</code> request against an HTTPS URL using proxy with username/password authorization (auth is required by the proxy not the website).
  Here's what I do:</p>
  
  <pre><code>package main
  
  import (
      "crypto/tls"
      "encoding/base64"
      "fmt"
      "net/http"
      "net/http/httputil"
      "net/url"
  )
  
  func main() {
      ua := "Mozilla/5.0 (Windows NT 6.1"
      basic := "Basic " + base64.StdEncoding.EncodeToString([]byte("username:mypass"))
      req, err := http.NewRequest("GET", "https://api.ipify.org/", nil)
      proxyUrl, _ := url.Parse("http://myproxy.com:9999")
      fmt.Println(basic) // Basic dXNlcm5hbWU6bXlwYXNz
      req.Header.Add("Proxy-Authorization", basic)
      req.Header.Add("User-Agent", ua)
      bb, _ := httputil.DumpRequest(req, false)
      fmt.Println(string(bb))
      /*
      Get / HTTP/1.1
      Host: api.ipify.org
      Proxy-Authorization: Basic dXNlcm5hbWU6bXlwYXNz
      User-Agent: Mozilla/5.0 (Windows NT 6.1
      */
      client := &amp;http.Client{
          Transport: &amp;http.Transport{
              TLSClientConfig: &amp;tls.Config{InsecureSkipVerify: true},
              Proxy:           http.ProxyURL(proxyUrl),
          },
      }
      resp, err := client.Do(req)
      fmt.Println(err)  // Proxy Authentication Required
      fmt.Println(resp) // &lt;nil&gt;
  }
  </code></pre>
  
  <p>The catch is that when I try to do a request to an HTTP (not HTTPS) site it goes fine, but if I make HTTPS request it fails (see above the message).</p>
  
  <p>I tested the proxy with my browser (FireFox) and everything goes well, I looked for the headers through firebug and added everything relevant to the request (above). I've double-triple-checked the <code>basic</code> value and everything else but without any luck.</p>
  
  <p>So does some one have any idea why this happens or at least how do I research the problem?</p>
  
  <p>The last thing to add is that I can use a public HTTP proxy (that doesn't require any auth) in this case and problems seem to start when auth enters in this process (the error also suggests that).</p>
  
  <p>P.S. Unfortunately I cannot share the proxy IP, port and username cause it is against their policy.</p>