On Fri, 14 Jun 2013, Spencer Elliott wrote:

*       Improve the function below, as I am not sure it's actually correct.

Ok, so you declare 'response' in the top...

        {
                std::string response;
                char data[128];

                curl_easy_setopt(curl, CURLOPT_USERAGENT, "User-Agent:
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0");
                curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
                curl_easy_setopt(curl, CURLOPT_POST, 1);
                sprintf(data, "%s:%s", WebAdminUserName, WebAdminPassword);
                curl_easy_setopt(curl, CURLOPT_USERPWD, data);
                sprintf(data, "UserName=%s&Password=%s", WebAdminUserName,
WebAdminPassword);
                curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);

Quoted from the CURLOPT_POSTFIELDS description of the man page:

  "The pointed data are NOT copied by the library: as a consequence, they must
  be preserved by the calling application until the transfer finishes."


                curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "cookie");
                curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "cookie");

                sprintf(data, "%s/ServerAdmin/current_console_send",
WebAdminURL);

... so here you overwrite the data you asked libcurl to send!

[snip]

                printf("\n");
                printf(response.c_str());

... and here you reference 'response' without ever having done anything with it.

I suggest you study the manuals closer and you follow the examples more closely.

--

 / daniel.haxx.se
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

Reply via email to