C++ libcurl - Server-Antwort von Standardausgabe umleiten

badday

Commander
Registriert
Sep. 2007
Beiträge
3.023
Moin zusammen,

ich verwende in einem Projekt libcurl und habe nun das Problem, dass die Antwort des Servers auf der Konsole ausgeben wird.

Ich poste also etwas und erhalte (falls erfolgreich) vom Server die Antwort "1". Dies wird momentan auf der Konsole ausgeben. Ich möchte die Antwort aber gerne in einer Funktion verarbeiten, wo also muss ich mich reinhängen, um diese Antwort abzufangen und an meine Funktion umzuleiten?

Ich verwende curl_easy_setopt mit der Option CURLOPT_POSTFIELDS.


Vielen Dank & Gruß,

badday
 
CURLOPT_WRITEFUNCTION

Function pointer that should match the following prototype: size_t function( void *ptr, size_t size, size_t nmemb, void *userdata); This function gets called by libcurl as soon as there is data received that needs to be saved. The size of the data pointed to by ptr is size multiplied with nmemb, it will not be zero terminated. Return the number of bytes actually taken care of. If that amount differs from the amount passed to your function, it'll signal an error to the library. This will abort the transfer and return CURLE_WRITE_ERROR.

From 7.18.0, the function can return CURL_WRITEFUNC_PAUSE which then will cause writing to this connection to become paused. See curl_easy_pause(3) for further details.

This function may be called with zero bytes data if the transferred file is empty.

Set this option to NULL to get the internal default function. The internal default function will write the data to the FILE * given with CURLOPT_WRITEDATA.

Set the userdata argument with the CURLOPT_WRITEDATA option.

The callback function will be passed as much data as possible in all invokes, but you cannot possibly make any assumptions. It may be one byte, it may be thousands. The maximum amount of data that can be passed to the write callback is defined in the curl.h header file: CURL_MAX_WRITE_SIZE.

CURLOPT_WRITEDATA

Data pointer to pass to the file write function. If you use the CURLOPT_WRITEFUNCTION option, this is the pointer you'll get as input. If you don't use a callback, you must pass a 'FILE *' as libcurl will pass this to fwrite() when writing data.

The internal CURLOPT_WRITEFUNCTION will write the data to the FILE * given with this option, or to stdout if this option hasn't been set.

If you're using libcurl as a win32 DLL, you MUST use the CURLOPT_WRITEFUNCTION if you set this option or you will experience crashes.

This option is also known with the older name CURLOPT_FILE, the name CURLOPT_WRITEDATA was introduced in 7.9.7.

http://curl.haxx.se/libcurl/c/curl_easy_setopt.html
 

Ähnliche Themen

Zurück
Oben