Changing data in postfields #12882
-
Hello everyone, a question arose, during the execution of my program, the string (the request body) changes and, accordingly, when trying to update the data for the curl query (when the string itself is updated), it simply does not do this, but uses the original data. Below is an example code of how it works. Thanks for the help void CurlMethod(Curl* _curl, std::string _dataPostString)
{
CURLcode res;
if (_curl != NULL)
{
curl_easy_setopt(_curl, CURLOPT_TIMEOUT, 100);
curl_easy_setopt(_curl, CURLOPT_URL, (const char*)_data_url.c_str());
curl_easy_setopt(_curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(_curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(_curl, CURLOPT_WRITEDATA, &_readBuffer);
curl_easy_setopt(_curl, CURLOPT_ACCEPT_ENCODING, "utf-8");
curl_easy_setopt(_curl, CURLOPT_HTTPHEADER, _headers);
curl_easy_setopt(_curl, CURLOPT_POSTFIELDS, _dataPostString.c_str()); // <- THIS Starting value
curl_easy_setopt(_curl, CURLOPT_VERBOSE, 1L);
res = curl_easy_perform(_curl);
if (res != CURLE_OK)
{
printf("\n# curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
}
else {
printf("\n# curl_easy_perform() compleet\n");
}
curl_easy_cleanup(_curl);
}
}
class main()
{
Curl* curl = curl_easy_init();;
CurlMethod( curl, _dataPostString.c_str());
if(ButonClick(""))
{
//The contents of the _data Post String change here (And it really changes)
...
//I'm trying to update the data for the request
curl_easy_setopt( _curl, CURLOPT_POSTFIELDS, __dataPostString.c_str());
}
}
The above code does not change postfields at all, what could be the reason? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
I don't understand what exactly you're trying to achieve, but in any case this |
Beta Was this translation helpful? Give feedback.
I don't understand what exactly you're trying to achieve, but in any case this
curl_easy_setopt( _curl, CURLOPT_POSTFIELDS, __dataPostString.c_str());
is executed after the request has been performed, and the handle destroyed!