# curl -H "Content-Type: application/json" -H "groupID: 268654" -X POST -d '{}' -v https://www-openapi.hualala.com/card/getCrmCustomerCards * About to connect() to www-openapi.hualala.com port 443 (#0) * Trying 106.15.155.28... * Connected to www-openapi.hualala.com (106.15.155.28) port 443 (#0) * Initializing NSS with certpath: sql:/etc/pki/nssdb * CAfile: /etc/pki/tls/certs/ca-bundle.crt CApath: none * SSL connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 * Server certificate: * subject: CN=*.hualala.com,O=北京多来点信息技术有限公司,ST=北京市,C=CN * start date: Jun 23 00:00:00 2020 GMT * expire date: Jun 27 12:00:00 2022 GMT * common name: *.hualala.com * issuer: CN=GeoTrust CN RSA CA G1,OU=www.digicert.com,O=DigiCert Inc,C=US > POST /card/getCrmCustomerCards HTTP/1.1 > User-Agent: curl/7.29.0 > Host: www-openapi.hualala.com > Accept: */* > Content-Type: application/json > groupID: 268654 > Content-Length: 2 > * upload completely sent off: 2 out of 2 bytes < HTTP/1.1 500 Internal Server Error < Date: Tue, 17 Nov 2020 11:49:42 GMT < Content-Type: application/json;charset=UTF-8 < Content-Length: 170 < Connection: keep-alive < Kepler-Agenttoken: Zl10WFsP < X-Application-Context: application:prod:8098 < * Connection #0 to host www-openapi.hualala.com left intact {"timestamp":1605613782836,"status":500,"error":"Internal Server Error","exception":"java.lang.NumberFormatException","message":"null","path":"/card/getCrmCustomerCards"}
可以看到,在不支持http2的环境里,是可以正常返回数据的.
如何解决
针对目前碰到的这个问题.只需要禁用客户端请求的http2功能即可
golang的 http.Client 禁用http2有两种方法
方法一: 使用GODEBUG环境变量
1
GODEBUG=http2client=0
golang的http.Client的 Transport 检测到有这个环境变量就不会走 http2
1 2 3 4 5 6 7 8 9 10 11 12
// D:\Go\src\net\http\transport.go
// onceSetNextProtoDefaults initializes TLSNextProto. // It must be called via t.nextProtoOnce.Do. func(t *Transport)onceSetNextProtoDefaults() { t.tlsNextProtoWasNil = (t.TLSNextProto == nil) if strings.Contains(os.Getenv("GODEBUG"), "http2client=0") { return }