drfb52000 2018-09-21 01:39
浏览 146
已采纳

简单的HTTPS请求:Golang返回505,Python和Chrome运行正常

I'm attempting to perform an HTTP get over TLS using the simplest imaginable golang code and getting a 505 response from a server (HTTP version not supported). The thing is, with a simple python requests.get the same query works. Also, I can use Chrome and perform the same request successfully.

Any ideas what makes the golang request different that would cause the server to return the 505?

I realize that this response is server specific. HTTPS to google.com with the same golang code works. I've attempted troubleshooting with Wireshark but TLS makes this difficult. It seems like this must be something simple! The server is nginx 1.9.3.

Golang code:

package main

import (
        "fmt"
        "net/http"
        "time"
)

func main() {
        url := "https://non-public-address/page"
        tr := &http.Transport{
                MaxIdleConns:       10,
                IdleConnTimeout:    30 * time.Second,
                DisableCompression: false,
        }
        client := &http.Client{Transport: tr}
        resp, _ := client.Get(url)
        fmt.Println(resp)
}

Python:

r = requests.get("https://non-public-address/page")
print(r)
  • 写回答

2条回答 默认 最新

  • duanjiani6826 2018-09-22 21:10
    关注

    I figured out the issue eventually by decrypting the traffic in Wireshark. The URL in my Go implementation has spaces and using http.Get didn't URL encode the spaces to %20. With spaces in the GET request the server was misinterpreting the request.

    Lesson learned: Go's http.Get does not URL encode characters and you have to do this on your own.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵