Witam.
Próbuję poprzez CURL zalogować się na stronę. Niestety bez skutku.
W Formularzu na stronie mam standardowe pola:
- User name
- Password
- Remember Me (checkbox)
- Submit (Button)
Oprócz tych pól mam jeszcze następujące:
<input type="hidden" name="temp" value="login" />
<input type="hidden" name="optional" value="curr" />
<input type="hidden" name="return" value="L5682plLWtvbnRvL2FjY291bnQuasdY70" />
<input type="hidden" name="6783a1e587240586997493939" value="1" /></form>
Mój kod wygląda tak ( w niewielkim stopniu przerobiony program z dokumentacji) :
#include <cstdlib>
#include <cstring>
#include <curl/curl.h>
#include <curl/easy.h>
int main(int argc, char** argv)
{
CURL* curl;
CURLcode res;
struct curl_httppost* formpost=NULL;
struct curl_httppost* lastptr=NULL;
struct curl_slist *headerlist=NULL;
static const char buf[] = "Expect:";
curl_global_init(CURL_GLOBAL_ALL);
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "username",
CURLFORM_COPYCONTENTS, "user", //username
CURLFORM_END);
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "passwd",
CURLFORM_COPYCONTENTS, "password", // my password
CURLFORM_END);
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "Submit",
CURLFORM_COPYCONTENTS, "Zaloguj",
CURLFORM_END);3d6a239dab3f
curl = curl_easy_init();
headerlist = curl_slist_append(headerlist, buf);
if (curl)
{
curl_easy_setopt(curl, CURLOPT_URL, "http://www.website.pl/index.php");
if ((argc == 2 ) && (!strcmp(argv[1], "noexpectheader")))
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
res = curl_easy_perform(curl);
if(res != CURLE_OK)
{
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
}
curl_easy_cleanup(curl);
curl_formfree(formpost);
curl_slist_free_all (headerlist);
}
return (EXIT_SUCCESS);
}
Niestety nie logowanie tym programem nie przechodzi.
Co z tymi ukrytymi polami ?
Będę wdzięczny za wskazówki od bardziej doświadczonych użytkowników.