grab包使用的坑,求解!!谢谢

jiahuaibo · · 161 次点击 · 开始浏览    置顶
func DownLog(storagepath, fileurl string) { client := grab.NewClient() //client.HTTPClient.Close = true connectTimeout := 10 * time.Second c := http.Client{ Transport: &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, Dial: TimeoutDialer(connectTimeout), }, } client.HTTPClient = &c //client = &http.Client{Transport: tr, Timeout: time.Duration(10) * time.Second} req, err := grab.NewRequest(storagepath, fileurl) req.HTTPRequest.Close = true if err != nil { Log.Println(fileurl, "err:", err) } resp := client.Do(req) if resp == nil { Log.Println("下载日志请求失败", "err:", err) return } if resp.HTTPResponse != nil { Log.Printf(fileurl, " %v\n", resp.HTTPResponse.Status) defer resp.HTTPResponse.Body.Close() } fmt.Println("3") t := time.NewTicker(1000 * time.Millisecond) defer t.Stop() Loop: for { select { case <-t.C: fmt.Printf(" transferred %v / %v bytes (%.2f%%)\n", resp.BytesComplete(), resp.Size, 100*resp.Progress()) case <-resp.Done: break Loop } } if err := resp.Err(); err != nil { Log.Println(os.Stderr, "Download failed: %v\n", fileurl) } Log.Printf("Download saved to %v \n", resp.Filename) } 下载文件会卡住,求解决办法 transferred 476126658200 / 484709804086 bytes (98.23%) transferred 476126658200 / 484709804086 bytes (98.23%) transferred 476126658200 / 484709804086 bytes (98.23%) transferred 476126658200 / 484709804086 bytes (98.23%) transferred 476126658200 / 484709804086 bytes (98.23%) transferred 476126658200 / 484709804086 bytes (98.23%) transferred 476126658200 / 484709804086 bytes (98.23%) transferred 476126658200 / 484709804086 bytes (98.23%) transferred 476126658200 / 484709804086 bytes (98.23%) transferred 476126658200 / 484709804086 bytes (98.23%) transferred 476126658200 / 484709804086 bytes (98.23%) transferred 476126658200 / 484709804086 bytes (98.23%) transferred 476126658200 / 484709804086 bytes (98.23%) transferred 476126658200 / 484709804086 bytes (98.23%) transferred 476126658200 / 484709804086 bytes (98.23%) transferred 476126658200 / 484709804086 bytes (98.23%) transferred 476126658200 / 484709804086 bytes (98.23%)
161 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传