我使用CURLOPT_COOKIEJAR (curl库),并将cookie保存在文件"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); 发布于 2016-05-17 13:26:48
当然你必须这么做。
你可以试试这段代码:
CURLOPT_COOKIEJAR=>__DIR__."/cookie.txt",或
CURLOPT_COOKIEJAR=>dirname(__FILE__)."/cookie.txt",发布于 2016-05-18 00:58:39
不需要绝对路径。清理cookie会话的CURLOPT_COOKIESESSION似乎与CURLOPT_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);https://stackoverflow.com/questions/30260694
复制相似问题