curl_easy_setopt()
that accept a string as its third argument.CURLOPT_POSTFIELDS
.CURLOPT_POSTFIELDS
CURLOPT_POSTFIELDS
only stores the pointer to the data, meaning an application using this option must keep the memory around for the entire duration of the associated transfer.CURLOPT_COPYPOSTFIELDS
which copies the data. If the data is binary and does not stop at the first presence of a null byte, make sure that CURLOPT_POSTFIELDSIZE
is set before this option is used.CURLOPT_POSTFIELDS
is an exception is due to legacy. Originally (before curl 7.17.0), libcurl did not copy any string arguments and when this current behavior was introduced, this option could not be converted over without breaking behavior so it had to keep working like before. Which now sticks out, as no other option does...c_str()
method.