我坚持使用 Golang 执行 get 请求,我也尝试了三种不同的实现,但都没有成功。对于他们所有人,我都收到此错误消息:
获取https://11.11.11.1:0000/httpgw.conf?Type=SMS&Address=12345678&MsgID=12 3&Notify=N&Validity=24:00&OAdC=15555&Message=HelloBrother: tls: 接收到长度为 207 的超大记录
Bellow 是我正在处理的整个源代码:
package main
import (
"crypto/tls"
"fmt"
"io/ioutil"
"net/http"
"os"
)
func main() {
cmdSecSMS := "https://11.11.11.1:0000/httpgw.conf?Type=SMS&Address=12345678&MsgID=123&Notify=N&Validity=24:00&OAdC=15555&Message="
msg := "HelloBrother"
cmdSecUrlSMS := cmdSecSMS + msg
doClientTrans(cmdSecUrlSMS)
doGetClient(cmdSecUrlSMS)
doGet(cmdSecUrlSMS)
}
func doClientTrans(address string) {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{Transport: tr}
response, err := client.Get(address)
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
} else {
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
}
fmt.Printf("%s\n", string(contents))
fmt.Println(" Size: ", len(string(contents)), " url: ", address)
fmt.Println(" Status Code: ", response.StatusCode)
hdr := response.Header
for key, value := range hdr {
fmt.Println(" ", key, ":", value)
}
}
}
func doGet(url string) {
response, err := http.Get(url)
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
} else {
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
}
我在 windows server 2012 中运行 golang 应用程序,但我对服务器技术堆栈一无所知。
有可能解决这个问题吗?有配置解决方法或我可以尝试的其他方法吗?
感谢您的帮助
慕婉清6462132
相关分类