dongmeiyi2266 2016-01-08 13:45
浏览 145
已采纳

收到长度为20527的net / http GET请求错误tls超大记录

I'm stucking to perform a get request using Golang and I also have tried three distinct implementations without success. For all them I'm receiving this error message:

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: oversized recor d received with length 20527

Bellow is the entire source code that I'm working on:

    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
", 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)
        }
        fmt.Println(" Size: ", len(string(contents)), " url: ", url)
        fmt.Println(" Status Code:  ", response.StatusCode)
        hdr := response.Header
        for key, value := range hdr {
            fmt.Println(" ", key, ":", value)
        }
    }
}

func doGetClient(url string) {
    client := &http.Client{}

    response, err := client.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)
        }
        fmt.Println(" Size: ", len(string(contents)), " url: ", url)
        fmt.Println(" Status Code: ", response.StatusCode)
        hdr := response.Header
        for key, value := range hdr {
            fmt.Println(" ", key, ":", value)
        }
    }
}

When using telnet, this GET request works normally:

telnet 11.11.11.1 0000

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 HTTP/1.1

^: exit

enter image description here

I'm running the golang app in the windows server 2012 and I don't know nothing about the server tech stack.

It's possible to fix this issue? There is a configuration workaround or something else that I can try?

thanks for your help

  • 写回答

1条回答 默认 最新

  • doutian3010 2016-01-14 18:09
    关注

    I'm glad to share with you that I reach the needed implementation.

    The code bellow works!

    Thanks for your comments that guide me to the right approach for this task:

    package main
    
    
    import (
     "bufio"
     "crypto/tls"
     "fmt"
     "io/ioutil"
     "net"
     "net/http"
     "os"
    )
    
    
    func main() {
    
    
     cmdSecSMS := "GET https://10.xxx.xx.x:xx43/httpgw.conf?" +
     "Type=SMS&Address=5511111&MsgID=123&Notify=N&Validity=24:00&OAdC=15555&" +
     "Message=blablah " +
     "HTTP/1.1"
    
    
     fmt.Println(cmdSecSMS)
     cmdSecUrlSMS := cmdSecSMS
     hostName := "10.xxx.xx.x"
     portNum := "xx43"
    
     doDial(cmdSecUrlSMS, hostName, portNum)
    
     //doClientTrans(cmdSecUrlSMS)
    
     //doGetClient(cmdSecUrlSMS)
    
     //doGet(cmdSecUrlSMS)
    
    }
    
    
    func doDial(cmd, host, port string) {
     // connect to this socket
     conn, err := net.Dial("tcp", host+":"+port)
    
    
     if err != nil {
     fmt.Printf("Some error %v", err)
     return
     } else {
     defer conn.Close()
     fmt.Printf("Connection established between %s and localhost.
    ", host)
     fmt.Printf("Local Address : %s 
    ", conn.LocalAddr().String())
     fmt.Printf("Remote Address : %s 
    ", conn.RemoteAddr().String())
    
    
     // send to socket
     fmt.Fprintf(conn, cmd+"
    ")
     // listen for reply
     message, _ := bufio.NewReader(conn).ReadString('
    ')
     fmt.Print("Message from server: " + message)
     }
    

    }

    Thank you guys for your support!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。