go-curl中使用OPT_COOKIEJAR選項時,有沒有辦法檢查作業是否完成?
如果運行下面的原始碼,會出現在cookie下載完成前執行ReadFile的問題。我想解決這個問題。
CommonSetopt(easy)
easy.Setopt(curl.OPT_VERBOSE, 0)
easy.Setopt(curl.OPT_COOKIEJAR, cookieName)
easy.Setopt(curl.OPT_URL, string("https://drive.google.com/uc?export=download&id=" gdriveID))
log.Println("start download cookie: ", url)
if err := easy.Perform(); err != nil {
log.Println("cookie download fail: ", err)
return
}
readBuf, err := ioutil.ReadFile(cookieName)
if err != nil {
log.Println("cookie read fail: ", err)
return
}
uj5u.com熱心網友回復:
您需要在之后立即清理會話easy.Perform而不是使用defer陳述句進行清理
CommonSetopt(easy)
easy.Setopt(curl.OPT_VERBOSE, 0)
easy.Setopt(curl.OPT_COOKIEJAR, cookieName)
easy.Setopt(curl.OPT_URL, string("https://drive.google.com/uc?export=download&id=" gdriveID))
log.Println("start download cookie: ", url)
if err := easy.Perform(); err != nil {
log.Println("cookie download fail: ", err)
easy.Cleanup()
return
}
// do cleanup
easy.Cleanup()
readBuf, err := ioutil.ReadFile(cookieName)
if err != nil {
log.Println("cookie read fail: ", err)
return
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/347818.html
上一篇:去redisHMSet失敗
