curl检索旧版本的page

curl retrieves old version of page

本文关键字:page 版本 检索 curl      更新时间:2023-10-16

我正在使用curl在我的bitbucket存储库中获取一个HTML文件。我不能给你直接的链接,因为回购是私人的,但它来自以下形式:https://bitbucket.org/uname/project/downloads/index.html

我使用以下代码:

mCurl = curl_easy_init();
curl_easy_setopt(mCurl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(mCurl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(mCurl, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(mCurl, CURLOPT_URL, String::toAnsi(address).c_str());
curl_easy_setopt(mCurl, CURLOPT_WRITEFUNCTION, _internal_curl_write_callback);
curl_easy_setopt(mCurl, CURLOPT_WRITEDATA, this);
curl_easy_perform(mCurl);

虽然一开始,在我更改页面(在repo上删除并上传新页面)后,结果似乎还可以,但即使我重新启动应用程序,curl仍然会检索页面的旧版本。但是,在浏览器中,如果我输入该链接,就会得到新的链接。

curl中有我可以禁用的缓存吗?或者你知道这种行为的其他可能的解释吗?

若要从服务器请求非缓存页面,请设置标头选项Cache-control: no-cache。您可以使用cURL:执行以下操作

struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Cache-control: no-cache");
curl_easy_setopt(mCurl, CURLOPT_HTTPHEADER, headers);

如果您在同一程序中重复使用连接,您可能还想启用:

curl_easy_setopt(mCurl, CURLOPT_FRESH_CONNECT, true);
curl_easy_setopt(mCurl, CURLOPT_FORBID_REUSE , true);