Unable to connect with HTTP proxy

go version: go1.13.5 linux/amd64

I am using “x/net/proxy” to connect with the “http_proxy”.

I have referred following proxy page: https://godoc.org/golang.org/x/net/proxy

To get proxy information I have set environment variable “all_proxy” to the the desired proxy “”, and performed the tcp connection, but following error is raised:

[Network Error : socks connect tcp>mx.eu1.mico.io:8883: read tcp> read: connection reset by peer]

I have looked “x/net/proxy”, It seems “http_proxy” support is not available instead of “SOCKS5” proxy is supported. I have similar implementation for “http_proxy”, but unfortunately it does not worked.

I have created a sample code (with port 1883) which is working for the non proxy environment, Please suggest how I can enable “http_proxy” or “https_proxy” support?

package main

import (


//The host address which we want to connect with the proxy
var host = "google.com:80"

func main() {
    fmt.Println("Inside main...")

    //Setting the proxy before starting the application
    if os.Getenv("http_proxy") == "" {
        os.Setenv("http_proxy", "")
    os.Setenv("all_proxy", os.Getenv("http_proxy"))

    if os.Getenv("all_proxy") != os.Getenv("http_proxy") {
        fmt.Println("Environment variables are not matching...")

    fmt.Println("System proxy is:", os.Getenv("all_proxy"))

    proxyDialer := proxy.FromEnvironment()

    fmt.Println("Connecting to...", host)

    conn, err := proxyDialer.Dial("tcp", host)
    if err != nil {
        fmt.Println("Unable to dial...", err)
    fmt.Println("Connected...", conn)
Inside main...
System proxy is:
Connecting to... google.com:80
Unable to dial... dial tcp connect: connection timed out

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.