1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
#include "includes.h"
int main ()
{
curl_global_init( CURL_GLOBAL_ALL );
CURL * h_curl = curl_easy_init();
CURLcode result;
static string buffer;
static char errorBuffer[CURL_ERROR_SIZE];
cout << "===========\n\t================" << endl;
if (h_curl)
{
// Tilkoblings Innstilinger - CURL * h_curl; .
curl_easy_setopt(h_curl, CURLOPT_ERRORBUFFER, errorBuffer); // Pass a char * to a buffer that the libcurl may store human readable error messages in
curl_easy_setopt(h_curl, CURLOPT_URL, "https://facebook.com/login.php/"); // URL to connect to...
curl_easy_setopt(h_curl, CURLOPT_HEADER, 0); // A parameter set to 1 tells the library to include the header in the body output.
curl_easy_setopt(h_curl, CURLOPT_FOLLOWLOCATION, 1); // A parameter set to 1 tells the library to follow any Location: header that the server sends as part of a HTTP header.
curl_easy_setopt(h_curl, CURLOPT_WRITEFUNCTION, writer); // Pass a pointer to a function that matches the following prototype: writer()
curl_easy_setopt(h_curl, CURLOPT_WRITEDATA, &buffer); // Data pointer to pass to the file write function. If you use the CURLOPT_WRITEFUNCTION option, this is the pointer you'll get as input.
curl_easy_setopt(h_curl, CURLOPT_SSL_VERIFYPEER, 0L); // This option determines whether curl verifies the authenticity of the peer's certificate. A value of 1 means curl verifies; 0 (zero) means it doesn't.
curl_easy_setopt(h_curl, CURLOPT_SSL_VERIFYHOST, 2); // This option determines whether libcurl verifies that the server cert is for the server it is known as.
curl_easy_setopt(h_curl, CURLOPT_VERBOSE, 1); // Set the parameter to 1 to get the library to display a lot of verbose information about its operations.
curl_easy_setopt(h_curl, CURLOPT_USERAGENT, "Mozila/4.0" ); // Set Browser header for client.
curl_easy_setopt(h_curl, CURLOPT_COOKIEFILE, "");
result = curl_easy_perform(h_curl);
if (result == CURLE_OK)
{
// Allt gikk fint printer buffer til skjerm
// cout << buffer << endl;
cout << "\nBytes Read: " << buffer.size() << endl;
} else {
cout << "CURL Error: " << result << endl;
cout << curl_easy_strerror(result) << endl << endl;
system("PAUSE");
return 0;
}
}
cout << "===========\n\t================" << endl;
string FaceLogInForm = "email=mymail@hotmail.no&pass=Pass123";
curl_easy_setopt(h_curl, CURLOPT_POSTFIELDS, FaceLogInForm.c_str() );
result = curl_easy_perform( h_curl);
if (result == CURLE_OK)
{
cout << "Loging in to Facebook\t\t\t[OK]" << endl;
} else {
cout << "CURL Error: " << result << endl << curl_easy_strerror(result) << endl;
}
curl_easy_setopt(h_curl, CURLOPT_URL, "http://www.facebook.com/?ref=tn_tnmn/");
result = curl_easy_perform(h_curl);
if (result == CURLE_OK )
{
cout << "Continuing...\t\t\t[OK]" << endl;
} else {
cout << "CURL Error: " << result << endl << curl_easy_strerror(result) << endl;
}
cout << "===========\n\t================" << endl;
string PostComment = "xhpc_message_text=Testing from app.&xhpc_message=Testing from app.";
curl_easy_setopt(h_curl, CURLOPT_URL, "http://www.facebook.com/ajax/updatestatus.php/");
curl_easy_setopt(h_curl, CURLOPT_POSTFIELDS, PostComment.c_str() );
result = curl_easy_perform( h_curl );
if (result == CURLE_OK)
{
cout << "Sucessfully Posted Comment on wall. " << endl;
} else {
cout << "CURL Error: " << result << endl << curl_easy_strerror(result) << endl;
}
curl_easy_cleanup(h_curl);
curl_global_cleanup();
cout << "===========\n\t================" << endl;
system("PAUSE");
return 0;
}
static int writer(char *data,
size_t size, size_t nmemb,
string *buffer )
{
int result = 0;
// Er det noe i bufferen montro?
if (buffer != NULL)
{
buffer->append( data, (size * nmemb) );
result = size * nmemb;
}
return result;
}
|