Re: how do i post json to a https ?
Date: Sat, 10 Jan 2015 03:14:58 -0500
On 1/9/2015 11:25 PM, redmond wrote:
> with all your recommandation,i have modified my code,please take a
> look at my code,is it correct?i reference the code from
Before you do anything else please review the libcurl documentation;
there's an overview at . Take a look at some of the examples as well.
Here are some things wrong with that code, probably not all:
Call curl_global_init once at the very beginning of the program rather
than for each object creation. Technically this is fine but the first
call should be before any other threads have started. See  for more
The debug callback will receive data that is not null terminated . If
you can print the data as a string you would only print 'size' number of
characters, eg printf("%.*s", size, data);
CURLOPT_POSTFIELDS does not copy the data . It's bad practice to set
CURLOPT_POSTFIELDS to a c_str because the pointer c_str returns could be
invalidated when the string is modified or destroyed.
The write function must return the amount of bytes handled, in this case
(size * nmemb). Also the number of bytes could be 0. See .
> i have question,due to my code is use as a dynamic link
> library,however the static size_t OnWriteData(void* buffer, size_t
> size, size_t nmemb, void* lpVoid) funcition is not allow using in
> dll,is it correct?how do i modify this function that i could use it in
I'm not sure what you mean by this. Why can't you use the callback in a DLL?
> //mycode is dll
I only took a brief look at this. I think you need help that is really
outside of the scope of this mailing list. A few things though:
Review dllexport/import at .
Your function's return value is either a curlcode or the value of
"returncode". That's bad practice, it will lead to trouble. I would have
return values specifically for your function and whether it failed or
succeeded. If the caller needs that extra information make it available
through output parameters, eg func( in1, in2, in3, CURLcode *out1,
then if(!func) caller can work with curlcode or server code if need be.
Actually given your number of input parameters I'd throw all that in a
struct and pass a pointer to it so func( JSONinput *in, CURLcode *out1,
ServerCode *out2) maybe.
Also that deserialize is wrong. If you need help with cJSON this list
can't help you, go to their help forum at . Also check out any C
programming forums, MSDN forums and stackoverflow.
List admin: http://cool.haxx.se/list/listinfo/curl-library
Received on 2015-01-10