使用简化版本的http post请求会带来一个很莫名其妙的error :EOF
这里有一些解法:
将简化版 的http post改为,client.Do(request),并将request.Close设置为true。
client := &http.Client{}
req, err := http.NewRequest(method, url, httpBody)
// NOTE this !!
req.Close = true
req.Header.Set("Content-Type", "application/json")
req.SetBasicAuth("user", "pass")
resp, err := client.Do(req)
if err != nil {
// whatever
}
defer resp.Body.Close()
response, err = ioutil.ReadAll(resp.Body)
if err != nil {
// Whatever
}
最后
以上就是寒冷万宝路最近收集整理的关于记一次golang 问题的处理的全部内容,更多相关记一次golang内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复