cURL / Mailing Lists / curl-library / Single Mail

curl-library

RE: Content-Type: application/x-www-form-urlencoded; SendText=say+This+is+a+test&Send=Send

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Sat, 15 Jun 2013 00:35:00 +0200 (CEST)

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
Received on 2013-06-15