记一次golang 问题的处理
发布时间:2020-12-16 18:40:33 所属栏目:大数据 来源:网络整理
导读:使用简化版本的http post请求会带来一个很莫名其妙的error :EOF 这里有一些解法: 将简化版 的http post改为,client.Do(request),并将request.Close设置为true。 client := http.Client{}req,err := http.NewRequest(method,url,httpBody)// NOTE this !!
使用简化版本的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 } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Perl和Ruby之间的YAML数据交换问题
- 在Perl中,我如何精确检查$变量是否已定义并包含非零长度字符
- .net – 格式化负的TimeSpan
- Visual Basic .NET and the .NET Platform: An Advanced Gu
- delphi – 当RowCount> VisibleRowCount没有选择网格的第一
- 如何在Delphi7中使用SQLServer Service Broker / SQLNotifi
- 基于泛型参数类型的类型推断(Delphi)
- 如何在Delphi 2007应用程序中显示Crystal XI报告?
- [VB.NET]困扰我几天的问题..一直想不出~~关于VB.NET的Event
- Perl:为什么“last”不用于退出grep或map?