cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: LibCurl C/C++ Authentification

From: Ralph Mitchell <ralphmitchell_at_gmail.com>
Date: Tue, 11 Jun 2013 14:21:55 -0400

On Jun 11, 2013 1:30 AM, "Spencer Elliott" <fm_reborn_at_hotmail.com> wrote:
>
> Ralph,
>
>
>
> I hope you do not mind me emailing you, it’s a bit random I guess, but I
saw your email in a public thread related to LibCurl authentification, and
I was hoping you might be able to help me.
>
>
>
> I have built an application (Win32 console) that joins an IRC server, and
listens to the chat, waiting for a command. This part is working fine.
>
> I have included the libcurl library into the application and performed
some simple examples.
>
> However, I want the application to log-into an admin panel for a game
server, and then perform some admin functions (the game server can only be
administrated from a web panel, and the ability to perform these functions
in IRC instead is something the users of this game really want).
>
>
>
> My challenge is that while I am okay programming in C++, I have very
little experience with cookies, http header files and libcurl.
>
> Would you be able to show me the correct method of logging in (and
assuming I want to stay authenticated while the session is open)? I know as
much that it requires POST and have tried with the following:
>
>
>
> void CurlPostTest()
>
> {
>
> CURL *curl;
>
> CURLcode res;
>
>
>
>
>
> curl_global_init(CURL_GLOBAL_ALL);
>
>
>
> curl = curl_easy_init();
>
> if(curl)
>
> {
>
> curl_easy_setopt(curl, CURLOPT_URL, "
http://208.115.205.106:8075/ServerAdmin/");
>
> curl_easy_setopt(curl,
CURLOPT_FOLLOWLOCATION, 1);
>
> curl_easy_setopt(curl, CURLOPT_POST, 1);
>
> curl_easy_setopt(curl,
CURLOPT_POSTFIELDS, "UserName=myname&Password=mypass");
>
> curl_easy_setopt(curl, CURLOPT_COOKIEJAR,
"cookie");
>
> curl_easy_setopt(curl,
CURLOPT_COOKIEFILE, "cookie");
>
>
>
> 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_global_cleanup();
>
> }
>
>
>
> However, this was largely guess work to be honest. It returns:
>
>
>
> <Title>401 Unauthorized</title><H1>401 Unauthorized</H1>
>
> Curl_easy_perform() failed: No error
>
>
>
> Based on the url http://208.115.205.106:8075/ServerAdmin/ would you know
what the correct post fields are? That string is really what I need, I
think (variablename=myname&passwordvairable=mypass).
>
> How do you determine what the field names are?
>
>
>
> If you felt really generous, would you mind changing the entire function
to log-in properly to the above the url? If I had an example, I’m sure I
could then do everything else I needed to.
>
>
>
> I appreciate this is a weird random request. However, I am hoping you
remember your own struggles as a newbie and are willing to help?

I've copied this to the libcurl mailing list, because you'll get a better
answer, faster.

I don't use c/c++ at all, so I can't even start to help you out.

Ralph Mitchell

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2013-06-11