CURLOPT_COOKIEJAR和cookie文件

CURLOPT_COOKIEJAR和cookie文件,curl,cookies,libcurl,Curl,Cookies,Libcurl,我正在使用CURLOPT_COOKIEJAR(curl库),并将cookies保存在一个文件“cookie.txt”中。我在档案里找不到它。它在哪里?我在项目文件夹中搜索,什么也没有 这是我的密码: curl_easy_setopt(handle,CURLOPT_COOKIESESSION,1); // clean up session. curl_easy_setopt(handle,CURLOPT_COOKIEJAR,"cookie.txt"); curl_easy_setopt

我正在使用CURLOPT_COOKIEJAR(curl库),并将cookies保存在一个文件“cookie.txt”中。我在档案里找不到它。它在哪里?我在项目文件夹中搜索,什么也没有

这是我的密码:

curl_easy_setopt(handle,CURLOPT_COOKIESESSION,1);       // clean up session.
curl_easy_setopt(handle,CURLOPT_COOKIEJAR,"cookie.txt");
curl_easy_setopt(handle,CURLOPT_USERAGENT,userAgentMozilla);        // set the user agent
curl_easy_setopt(handle,CURLOPT_URL,lien.toUtf8().constData());     // set the url 
curl_easy_setopt(handle,CURLOPT_POSTFIELDSIZE,data.size()+4);     // size of the request.
curl_easy_setopt(handle,CURLOPT_POSTFIELDS,ba);  // aray of the POST request
res = curl_easy_perform(handle);  

你当然得这么做

您可以尝试以下代码:

CURLOPT_COOKIEJAR=>__DIR__."/cookie.txt",

CURLOPT_COOKIEJAR=>dirname(__FILE__)."/cookie.txt",

不需要绝对路径。 清理cookie会话的
CURLOPT\u-COOKIESESSION
似乎与
CURLOPT\u-COOKIEJAR
冲突。这不会清理cookie会话,处理请求,然后将新cookie保存到文件中。但是,这将阻止在此请求中创建新的cookie会话。 正确的代码应该是:

curl_easy_setopt(handle,CURLOPT_COOKIEJAR,"cookie.txt");
curl_easy_setopt(handle,CURLOPT_USERAGENT,userAgentMozilla);        // set the user agent
curl_easy_setopt(handle,CURLOPT_URL,lien.toUtf8().constData());     // set the url 
curl_easy_setopt(handle,CURLOPT_POSTFIELDSIZE,data.size()+4);     // size of the request.
curl_easy_setopt(handle,CURLOPT_POSTFIELDS,ba);  // aray of the POST request
res = curl_easy_perform(handle);

我必须设置一条绝对路径吗?不需要绝对路径。看看我的答案。