ฉันมีปัญหาในการส่งคำขอไปยัง URL เฉพาะ (เป็นการแลกเปลี่ยนเมลเซิร์ฟเวอร์) ในสภาพแวดล้อมการใช้งานจริง
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)
แต่รหัสนี้ส่งคืนข้อผิดพลาด:
Get "https://mail.example.com": read tcp [server_ip]:53006->[destination_server_ip]:443: read: connection timed out
หลังจากป้องกันการเปลี่ยนเส้นทาง:
client := http.Client{
Transport: tr,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
}
ข้อผิดพลาดเปลี่ยนเป็น:
Get "https://mail.example.com": read tcp [server_ip]:53120->[destination_server_ip]:443: read: connection reset by peer
โค้ดด้านบนยังทำงานได้ดีในสภาพแวดล้อมท้องถิ่น
แต่ Linux curl ในเซิร์ฟเวอร์ (เซิร์ฟเวอร์ที่ใช้งานจริงที่โค้ด Go ทำงานได้ไม่ดี) ทำงานได้ดี:
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
ฉันคิดว่าปัญหาเกิดขึ้นกับไฟร์วอลล์ (ไฟร์วอลล์ CentOS) และฉันหยุดมันแล้ว แต่ฉันยังคงมีปัญหาอยู่
curl
ไม่ใช่ ดูการตอบสนองที่แตกต่างจาก cURL และ Golang POST, ฉันจะทำให้ไคลเอ็นต์ Go HTTP ไม่ติดตามการเปลี่ยนเส้นทางโดยอัตโนมัติได้อย่างไร - 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