Golang HTTP download transfer specified domain IP/host IP

Golang HTTP download transfer specified domain IP/host IP

package main

import (
    "context"
    "log"
    "net"
    "time"
    "net/http"
)

func main() {
    dialer := &net.Dialer{
        Timeout:   60 * time.Second,
        KeepAlive: 60 * time.Second,
    }
    http.DefaultTransport.(*http.Transport).DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
        if addr == "www.baidu.com:80" {
            addr = "14.215.177.39:80"
        }
        return dialer.DialContext(ctx, network, addr)
    }
    resp, err := http.Get("http://www.baidu.com")
    log.Println(resp.Header, err)
}

Comments

Popular posts from this blog

Python Receiving and parse JSON Data via UDP protocol

ubus lua client method and event registration code demo/example