问题如下:
curl -i --location --request POST 'https://api.xxx.com/coupon/info/list'
--header 'accessKey: AEf'
--header 'accessToken: EE0BB88263F73D19F5074E9D1910739F'
--header 'timestamp: 1666087720519'
--header 'Content-Type: application/json'
--data '{
"channelCode": "TMALL",
"couponStatus": [
15
],
"pageNo": 1,
"pageSize": 3,
"source": "TMALL",
"asid": "tmJDDFI003"
}'
在宿主机内请求 accessKey 可以在接收方得到原样的索引值,但是在容器内获取请求,接收方却变成了 accesskey
经过上面的curl -i信息得知道 宿主机内走的http1.1协议 ,容器内走的却是http2协议
在容器内加上 --http1.1 指定http协议版本如下:
curl --http1.1 -i --location --request POST 'https://api.xxx.com/coupon/info/list'
--header 'accessKey: AEf'
--header 'accessToken: EE0BB88263F73D19F5074E9D1910739F'
--header 'timestamp: 1666087720519'
--header 'Content-Type: application/json'
--data '{
"channelCode": "TMALL",
"couponStatus": [
15
],
"pageNo": 1,
"pageSize": 3,
"source": "TMALL",
"asid": "tmJDDFI003"
}'
接收方获取的数据正常保持原样key
经查相关文档: http1.1对大小写不敏感,但是会在传输过程中保持原样的索引,http2则是会自动转成符合rfc标准的索引值
查相关的Golang代码,发现是因为域名走的https协议,代码层面,
http.transport默认会对https协议进行http2强制尝试,所以有下面改良代码,对https的安全验证跳过检查
tls.Config{InsecureSkipVerify: true},因为对方实际上使用的http1.1
//跳过证书验证tr := &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, } request.Header = make(http.Header) request.Header = header request.Header.Set("Content-Type", "application/json;charset=UTF-8") //添加请求头 client := http.Client{ Timeout: time.Second * 10, Transport: tr, } //创建客户端 resp, err := client.Do(request.WithContext(context.TODO())) //发送请求 if resp == nil && err != nil { return nil, err }