https://developers.weixin.qq.com/miniprogram/dev/api/network/request/wx.request.html
Header参数经过wx.request()函数处理后全部被转换为小写,导致遵从W3C标准(首字母大写)的硬件设备无法正确处理请求发生异常。
# 业务代码,header指定参数首字母大写:Content-Type
await asyncWraper(Taro.request)({
url: useMenue().deviceInfo.ipAddr,
header: {'Content-Type': data.contentType},
method: 'POST',
data: data.buffer
})
# 微信SDK,header指定参数首字母大写:Content-Type,实际发起HTTP请求后会变成小写:content-type
wx.request({
url: "http://" + ipVal,
header:{"Content-Type": data.contentType},
method:"POST",
data: data.buffer,
success: function success(res){postResponseText.value = "API response:" + JSON. stringify(res.data);}
});
# 实际请求如图,Content-Type变为小写
SDK包应当根据W3C标准对Header参数自动转换首字母大写
请仔细阅读 RFC 2616 。
https://datatracker.ietf.org/doc/html/rfc2616#section-4.2
Each header field consists of a name followed by a colon (":") and the field value. Field names are case-insensitive.