I’m using C and libcurl to log in to a website and retrieve a value from the form(ie put the string “username=random” into a char array). This is what I have so far:
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/4.0");
curl_easy_setopt(curl, CURLOPT_AUTOREFERER, 1 );
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1 );
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, " ");
curl_easy_setopt(curl, CURLOPT_URL, "http://www.website.com/login");
curl_easy_perform(curl);
curl_easy_setopt(curl, CURLOPT_REFERER, "http://www.website.com/login");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS,fields );
curl_easy_perform(curl);
curl_easy_setopt(curl, CURLOPT_URL, "http://www.website.com/form-with-data");
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
but I’m not sure where to go from there. I’ve tried writing the whole page into a file then manually searching for the string, but that did not work.
I’m sure there is a simple answer for this, I’m just new to both C and libcurl 🙂
Your current code will do one thing: it will write the data to the standard output. To accumulate the data, you have to do something like this: