I can't establish connection with proxy with auth


Every time i try to connect through a proxy auth i got an error, it worked well without auth.

Thier is the error :

panic: runtime error: invalid memory address or nil pointer dereference [signal 0xc0000005 code=0x0 addr=0x40 pc=0x4d3c79]

goroutine 1 [running]: main.main() C:/Users/Administrator/Desktop/go lang/cmdtes/goll.go:23 +0x259 exit status 2

My code

package main

import "fmt"
import "net/url"
import "encoding/base64"
import "net/http"
import "io/ioutil"
func main() {
    proxyStr := "https://proxy:port"
    proxyURL, _ := url.Parse(proxyStr)
    auth := "username:password"
    basicAuth := "Basic " + base64.StdEncoding.EncodeToString([]byte(auth))
    hdr := http.Header{}
    hdr.Add("Proxy-Authorization", basicAuth)
    transport := &http.Transport{
        Proxy: http.ProxyURL(proxyURL),
        ProxyConnectHeader: hdr,

   client := &http.Client{Transport: transport}
   resp, _ := client.Get("https://example.com")
   defer resp.Body.Close()
   buf, _ := ioutil.ReadAll(resp.Body)
asked on Stack Overflow Oct 27, 2020 by lou cjcj • edited Oct 27, 2020 by Flimzy

0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0