网络/HTTP GET请求错误:tls接收到长度为20527的超大记录。

huangapple go评论114阅读模式
英文:

net/http GET request error tls oversized record received with length 20527

问题

我卡在使用Golang执行GET请求的过程中,我尝试了三种不同的实现方式,但都没有成功。对于所有这些实现方式,我都收到了以下错误消息:

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

下面是我正在使用的完整源代码:

  1. package main
  2. import (
  3. "crypto/tls"
  4. "fmt"
  5. "io/ioutil"
  6. "net/http"
  7. "os"
  8. )
  9. func main() {
  10. cmdSecSMS := "https://11.11.11.1:0000/httpgw.conf?Type=SMS&Address=12345678&MsgID=123&Notify=N&Validity=24:00&OAdC=15555&Message="
  11. msg := "HelloBrother"
  12. cmdSecUrlSMS := cmdSecSMS + msg
  13. doClientTrans(cmdSecUrlSMS)
  14. doGetClient(cmdSecUrlSMS)
  15. doGet(cmdSecUrlSMS)
  16. }
  17. func doClientTrans(address string) {
  18. tr := &http.Transport{
  19. TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
  20. }
  21. client := &http.Client{Transport: tr}
  22. response, err := client.Get(address)
  23. if err != nil {
  24. fmt.Printf("%s", err)
  25. os.Exit(1)
  26. } else {
  27. defer response.Body.Close()
  28. contents, err := ioutil.ReadAll(response.Body)
  29. if err != nil {
  30. fmt.Printf("%s", err)
  31. os.Exit(1)
  32. }
  33. fmt.Printf("%s\n", string(contents))
  34. fmt.Println(" Size: ", len(string(contents)), " url: ", address)
  35. fmt.Println(" Status Code: ", response.StatusCode)
  36. hdr := response.Header
  37. for key, value := range hdr {
  38. fmt.Println(" ", key, ":", value)
  39. }
  40. }
  41. }
  42. func doGet(url string) {
  43. response, err := http.Get(url)
  44. if err != nil {
  45. fmt.Printf("%s", err)
  46. os.Exit(1)
  47. } else {
  48. defer response.Body.Close()
  49. contents, err := ioutil.ReadAll(response.Body)
  50. if err != nil {
  51. fmt.Printf("%s", err)
  52. os.Exit(1)
  53. }
  54. fmt.Println(" Size: ", len(string(contents)), " url: ", url)
  55. fmt.Println(" Status Code: ", response.StatusCode)
  56. hdr := response.Header
  57. for key, value := range hdr {
  58. fmt.Println(" ", key, ":", value)
  59. }
  60. }
  61. }
  62. func doGetClient(url string) {
  63. client := &http.Client{}
  64. response, err := client.Get(url)
  65. if err != nil {
  66. fmt.Printf("%s", err)
  67. os.Exit(1)
  68. } else {
  69. defer response.Body.Close()
  70. contents, err := ioutil.ReadAll(response.Body)
  71. if err != nil {
  72. fmt.Printf("%s", err)
  73. os.Exit(1)
  74. }
  75. fmt.Println(" Size: ", len(string(contents)), " url: ", url)
  76. fmt.Println(" Status Code: ", response.StatusCode)
  77. hdr := response.Header
  78. for key, value := range hdr {
  79. fmt.Println(" ", key, ":", value)
  80. }
  81. }
  82. }

当使用telnet时,这个GET请求正常工作:

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

我在Windows Server 2012上运行Golang应用程序,对服务器技术栈一无所知。

有可能解决这个问题吗?是否有配置解决方法或其他我可以尝试的方法?

谢谢你的帮助。

英文:

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:

  1. package main
  2. import (
  3. "crypto/tls"
  4. "fmt"
  5. "io/ioutil"
  6. "net/http"
  7. "os"
  8. )
  9. func main() {
  10. cmdSecSMS := "https://11.11.11.1:0000/httpgw.conf?Type=SMS&Address=12345678&MsgID=123&Notify=N&Validity=24:00&OAdC=15555&Message="
  11. msg := "HelloBrother"
  12. cmdSecUrlSMS := cmdSecSMS + msg
  13. doClientTrans(cmdSecUrlSMS)
  14. doGetClient(cmdSecUrlSMS)
  15. doGet(cmdSecUrlSMS)
  16. }
  17. func doClientTrans(address string) {
  18. tr := &http.Transport{
  19. TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
  20. }
  21. client := &http.Client{Transport: tr}
  22. response, err := client.Get(address)
  23. if err != nil {
  24. fmt.Printf("%s", err)
  25. os.Exit(1)
  26. } else {
  27. defer response.Body.Close()
  28. contents, err := ioutil.ReadAll(response.Body)
  29. if err != nil {
  30. fmt.Printf("%s", err)
  31. os.Exit(1)
  32. }
  33. fmt.Printf("%s\n", string(contents))
  34. fmt.Println(" Size: ", len(string(contents)), " url: ", address)
  35. fmt.Println(" Status Code: ", response.StatusCode)
  36. hdr := response.Header
  37. for key, value := range hdr {
  38. fmt.Println(" ", key, ":", value)
  39. }
  40. }
  41. }
  42. func doGet(url string) {
  43. response, err := http.Get(url)
  44. if err != nil {
  45. fmt.Printf("%s", err)
  46. os.Exit(1)
  47. } else {
  48. defer response.Body.Close()
  49. contents, err := ioutil.ReadAll(response.Body)
  50. if err != nil {
  51. fmt.Printf("%s", err)
  52. os.Exit(1)
  53. }
  54. fmt.Println(" Size: ", len(string(contents)), " url: ", url)
  55. fmt.Println(" Status Code: ", response.StatusCode)
  56. hdr := response.Header
  57. for key, value := range hdr {
  58. fmt.Println(" ", key, ":", value)
  59. }
  60. }
  61. }
  62. func doGetClient(url string) {
  63. client := &http.Client{}
  64. response, err := client.Get(url)
  65. if err != nil {
  66. fmt.Printf("%s", err)
  67. os.Exit(1)
  68. } else {
  69. defer response.Body.Close()
  70. contents, err := ioutil.ReadAll(response.Body)
  71. if err != nil {
  72. fmt.Printf("%s", err)
  73. os.Exit(1)
  74. }
  75. fmt.Println(" Size: ", len(string(contents)), " url: ", url)
  76. fmt.Println(" Status Code: ", response.StatusCode)
  77. hdr := response.Header
  78. for key, value := range hdr {
  79. fmt.Println(" ", key, ":", value)
  80. }
  81. }
  82. }

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

网络/HTTP GET请求错误:tls接收到长度为20527的超大记录。

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

得分: 1

我很高兴地与你分享,我已经完成了所需的实现。

下面的代码是有效的!

感谢你的评论,指导我选择了正确的方法来完成这个任务:

  1. package main
  2. import (
  3. "bufio"
  4. "crypto/tls"
  5. "fmt"
  6. "io/ioutil"
  7. "net"
  8. "net/http"
  9. "os"
  10. )
  11. func main() {
  12. cmdSecSMS := "GET https://10.xxx.xx.x:xx43/httpgw.conf?" +
  13. "Type=SMS&Address=5511111&MsgID=123&Notify=N&Validity=24:00&OAdC=15555&" +
  14. "Message=blablah " +
  15. "HTTP/1.1"
  16. fmt.Println(cmdSecSMS)
  17. cmdSecUrlSMS := cmdSecSMS
  18. hostName := "10.xxx.xx.x"
  19. portNum := "xx43"
  20. doDial(cmdSecUrlSMS, hostName, portNum)
  21. //doClientTrans(cmdSecUrlSMS)
  22. //doGetClient(cmdSecUrlSMS)
  23. //doGet(cmdSecUrlSMS)
  24. }
  25. func doDial(cmd, host, port string) {
  26. // connect to this socket
  27. conn, err := net.Dial("tcp", host+":"+port)
  28. if err != nil {
  29. fmt.Printf("Some error %v", err)
  30. return
  31. } else {
  32. defer conn.Close()
  33. fmt.Printf("Connection established between %s and localhost.\n", host)
  34. fmt.Printf("Local Address : %s \n", conn.LocalAddr().String())
  35. fmt.Printf("Remote Address : %s \n", conn.RemoteAddr().String())
  36. // send to socket
  37. fmt.Fprintf(conn, cmd+"\n")
  38. // listen for reply
  39. message, _ := bufio.NewReader(conn).ReadString('\n')
  40. fmt.Print("Message from server: " + message)
  41. }
  42. }
  43. Thank you guys for your support!

谢谢你们的支持!

英文:

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:

  1. package main
  2. import (
  3. "bufio"
  4. "crypto/tls"
  5. "fmt"
  6. "io/ioutil"
  7. "net"
  8. "net/http"
  9. "os"
  10. )
  11. func main() {
  12. cmdSecSMS := "GET https://10.xxx.xx.x:xx43/httpgw.conf?" +
  13. "Type=SMS&Address=5511111&MsgID=123&Notify=N&Validity=24:00&OAdC=15555&" +
  14. "Message=blablah " +
  15. "HTTP/1.1"
  16. fmt.Println(cmdSecSMS)
  17. cmdSecUrlSMS := cmdSecSMS
  18. hostName := "10.xxx.xx.x"
  19. portNum := "xx43"
  20. doDial(cmdSecUrlSMS, hostName, portNum)
  21. //doClientTrans(cmdSecUrlSMS)
  22. //doGetClient(cmdSecUrlSMS)
  23. //doGet(cmdSecUrlSMS)
  24. }
  25. func doDial(cmd, host, port string) {
  26. // connect to this socket
  27. conn, err := net.Dial("tcp", host+":"+port)
  28. if err != nil {
  29. fmt.Printf("Some error %v", err)
  30. return
  31. } else {
  32. defer conn.Close()
  33. fmt.Printf("Connection established between %s and localhost.\n", host)
  34. fmt.Printf("Local Address : %s \n", conn.LocalAddr().String())
  35. fmt.Printf("Remote Address : %s \n", conn.RemoteAddr().String())
  36. // send to socket
  37. fmt.Fprintf(conn, cmd+"\n")
  38. // listen for reply
  39. message, _ := bufio.NewReader(conn).ReadString('\n')
  40. fmt.Print("Message from server: " + message)
  41. }

}

Thank you guys for your support!

huangapple
  • 本文由 发表于 2016年1月8日 21:45:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/34678564.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定