英文:
Questions about go-curl's OPT_COOKIEJAR option
问题
在使用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
}
英文:
When using the OPT_COOKIEJAR option in go-curl, is there a way to check whether the work is completed?
If you run the source code below, there is a problem that ReadFile is executed before the cookie download is completed. I want to solve this.
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
}
答案1
得分: 2
你需要在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("开始下载cookie: ", url)
if err := easy.Perform(); err != nil {
log.Println("cookie下载失败: ", err)
easy.Cleanup()
return
}
// 进行清理
easy.Cleanup()
readBuf, err := ioutil.ReadFile(cookieName)
if err != nil {
log.Println("cookie读取失败: ", err)
return
}
英文:
You need to cleanup the session immediately after easy.Perform
instead of cleaning up using a defer
statement
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
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论