Adding a string in a CURL post variables
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "submit",
CURLFORM_COPYCONTENTS, "send",
CURLFORM_END);
This up there works just fine the POST key comes with “submit” in the page content.
but this:
string post = "submit";
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, &post,
CURLFORM_COPYCONTENTS, "send",
CURLFORM_END);
but this up here the page content in result comes with a extra weird character like “◘ER☺submit” instead of clean “submit”
what am I missing here? thanks!
You should use
std::string::c_str():By using
&post, you are extracting the address of thestd::string, which is a completely different data type than aconst char*you used when simply using the quoted string.std::string::c_str, on the other hand, returns theconst char *that actually stores the string.EDIT: regarding your concatenation question,
std::stringcan be concatenated. Therefore: