网站上的 libcurl http auth

libcurl http auth on site

我在站点中使用 libcurl 进行身份验证。我做的有很多功能,例如:

char *CheckLoginPass(char *login, char *pass)
{
  //use curl_easy_setopt for check login/pass
  return stdout;
} 

char *AuthOnSite() //make auth on site
{
  //use curl_easy_setopt for auth by login/pass
  return htmlpage;
}

char *TestMyAuth()
{
  //use curl_easy_setopt for test auth
  return htmlpage;
}

void Test()
{
  char *stdout = CheckLoginPass("login", "pass"); // is good
  char *htmlpage = AuthOnSite(); // is good
  htmlpage = TestMyAuth(); // session is lose and I am not logined on site
}

如何避免丢失会话?

您需要为 libcurl 配置 "cookie jar" 以存储其会话 cookie,请参阅:https://curl.haxx.se/libcurl/c/CURLOPT_COOKIEJAR.html and refer to that when you make the TestMyAuth call, see: https://curl.haxx.se/libcurl/c/CURLOPT_COOKIEFILE.html