A preserved archive of the Logical Gamers community forums, 2009-2025. The original threads and posts, served read-only. Registration, posting and private messages are gone for good.

[Question] Form POST via C++ libcURL

871 views · started by 323 ·
#1
[Question] Form POST via C++ libcURL
Would this work for a simple form post?

It's using the libcURL libraries for C++

I'm going to upgrade it from here and add captcha support and stuff.

This is just the form submit.


/* This is a Gaia Online account creator
** Written by 323 for Logical Gamers
** Version 1.0
** Created 10-25-2012
** Check www.LogicalGamers.com for updates
*/

#include <stdio.h>
#include <string.h>

#include <curl/curl.h>

string userpassword = "password101";

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);

//Fill in the username field

curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "username",
CURLFORM_COPYCONTENTS, "RANDOMLY_GENERATED_STRING_HERE",
CURLFORM_END);

//Fill in the email field

curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "email",
CURLFORM_COPYCONTENTS, "ADD_YOUR_EMAIL_ADDRESS_HERE",
CURLFORM_END);

//Fill in the password field

curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "password",
CURLFORM_COPYCONTENTS, userpassword, //make the user's password the string userpassword (password101)

//Fill in the confirm password field

curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "password_confirm",
CURLFORM_COPYCONTENTS, userpassword,
CURLFORM_END);

//Fill in the date of birth month field

curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "dob_month",
CURLFORM_COPYCONTENTS, "1",
CURLFORM_END);

//Fill in the date of birth day field

curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "dob_day",
CURLFORM_COPYCONTENTS, "1",
CURLFORM_END);

//Fill in the date of birth year field

curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "dob_year",
CURLFORM_COPYCONTENTS, "1980",
CURLFORM_END);

//Fill in the submit field too, even if this is rarely needed

curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "submit",
CURLFORM_COPYCONTENTS, "send",
CURLFORM_END);
curl = curl_easy_init();

//initalize custom header list (stating that Expect: 100-continue is not wanted

headerlist = curl_slist_append(headerlist, buf);
if(curl) {

//what URL that receives this POST

curl_easy_setopt(curl, CURLOPT_URL, "http://avatarsave.gaiaonline.com/register/html/?step=userinfo&amp;_gaia_t_=296");
if ( (argc == 2) && (!strcmp(argv[1], "noexpectheader")) )

//only disable 100-continue header if explicitly requested

curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);

//Perform the request, res will get the return code

res = curl_easy_perform(curl);

//Check for errors

if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));

//always cleanup

curl_easy_cleanup(curl);

//then cleanup the formpost chain

curl_formfree(formpost);

//free slist

curl_slist_free_all (headerlist);
}
return 0;
}
[/1]
#2
This code looks bad and you should feel bad.

Jesus Christ, my eyes.
#3
This code looks bad and you should feel bad.

Jesus Christ, my eyes.


Well it was the example code on the official website, so suck my fucking dick. All I did was change the field names and add like two more.

You think it's bad code? Go complain to the developers of cURL.
#4
You think it's bad code? Go complain to the developers of cURL.


I think I'll complain to you instead for not knowing how abstractions work.

Take your spaghetti code elsewhere, Flare.