libcurl, c ++, CURLOPT_POSTFIELDS, post garbled contents, or change the length

to sum up:

A local variable, space is released; cause curl upon transmission, the data fail to


Detailed description:

In one project, use http libcurl send a message, use the post way; in the process of testing, found that sometimes, there will be an exception message is sent, see print out the information, found that information along with the back post to be wrong, the lack of content, or garbled




He studied for a long time, by checking the data, before deciding to set CURLOPT_POSTFIELDS this parameter, just pass a pointer to the instance of the curl. When the internal call, this will get pointers to take a specific value; if the entire process in one function, szField that I pass in this array of pointers will not be freed, everything is normal. But when I called, packaging has become a function here, returned to the upper calling, so the local variable szField space was freed up,

Wait until the curl content sent to fetch the content can change, it will lead to an error, or even hang

Guess you like

Origin blog.csdn.net/qq_34326603/article/details/80997658