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)
fmt.Println(string(buf))
}
User contributions licensed under CC BY-SA 3.0