cURL / Mailing Lists / curl-library / Single Mail

curl-library

Strange behavior of CURLOPT_POSTFIELDS

From: Bian, Jiang <JBian_at_uams.edu>
Date: Mon, 17 Dec 2012 18:20:32 +0000

Hi,

I have been scratch my for a couple hours and can't figure out what's wrong...

I am implementing a app that uses libcurl to post data to the sites for login.

One strange thing is:

if I have a const char* string literal in CURLOPT_POSTFIELDS it works. If it's not coming from a literal, it fails.

See the code below... paramsString is generated from a std::map<string, string> and properly url encoded.

As a matter of fact, I even tested whether paramsString is the same as the intended string literal, which it is.

Basically, what I am saying is if I do

 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, paramsString);

it fails. But if I do,

 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "submit_login_form=Login&txt_password= whatever&txt_username= test");

It works... despite the fact that paramsString is the same as "submit_login_form=Login&txt_password= whatever&txt_username= test". Tested with strcmp.

What could be the problem? My source code is UTF-8 encoded? Thanks!!!

curl_easy_setopt(curl, CURLOPT_POST, 1);

const char * paramsString = this->parameterString(); //function to generate url encoded string from std::map

if(strcmp(paramsString, "submit_login_form=Login&txt_password=whatever&txt_username=test") == 0){

LOG_DEBUG(LOG_TAG, "equal...");

paramsString = "submit_login_form=Login&txt_password= whatever&txt_username= test";

 }

 LOG_DEBUG(LOG_TAG, "%d %s", strlen(paramsString), paramsString);

 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, paramsString);

Thanks!

Jiang
Confidentiality Notice: This e-mail message, including any attachments,
is for the sole use of the intended recipient(s) and may contain
confidential and privileged information. Any unauthorized review,
use, disclosure or distribution is prohibited. If you are not the
intended recipient, please contact the sender by reply
e-mail and destroy all copies of the original message.

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-12-17