Saya memiliki masalah saat mengirim permintaan ke URL tertentu (ini adalah pertukaran server email) di lingkungan produksi.
tr := &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
}
client := http.Client{
Transport: tr,
}
req, _ := http.NewRequest("GET", "https://mail.example.com", nil)
req.Header.Set("Host", "mail.example.com")
req.Header.Set("User-Agent", "curl/7.29.0")
req.Header.Set("Accept", "*/*")
_, err := client.Do(req)
Namun kode ini mengembalikan kesalahan:
Get "https://mail.example.com": read tcp [server_ip]:53006->[destination_server_ip]:443: read: connection timed out
setelah mencegah pengalihan:
client := http.Client{
Transport: tr,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
}
kesalahan diubah menjadi:
Get "https://mail.example.com": read tcp [server_ip]:53120->[destination_server_ip]:443: read: connection reset by peer
Kode di atas juga berfungsi dengan baik di lingkungan lokal.
Namun Linux curl di server (server produksi yang kode Go-nya tidak berfungsi dengan baik) berfungsi dengan baik:
curl -I https://mail.example.com
HTTP/1.1 301 Moved Permanently
Cache-Control: no-cache
Pragma: no-cache
Content-Length: 0
Location: https://mail.example.com/owa/
Server: Microsoft-IIS/8.5
X-Powered-By: ASP.NET
Date: Thu, 15 Apr 2021 10:00:46 GMT
Connection: close
Saya pikir masalahnya ada pada firewall (Firewall CentOS) dan saya menghentikannya, tetapi saya masih mengalami masalah.
curl
tidak. Lihat Respon Berbeda Dari cURL dan Golang POST, Bagaimana Saya Dapat Membuat Klien HTTP Go TIDAK Mengikuti Pengalihan Secara Otomatis? - person Cerise Limón   schedule 15.04.2021Get "https://mail.example.com": read tcp [server_ip]:53120->[destination_server_ip]:443: read: connection reset by peer
- person AGH   schedule 15.04.2021