curl-library
RE: Redirect Ouput to a variable in dll
Date: Sun, 6 May 2012 12:18:28 +0000
>So, i need the output must be saved in a variable instead of writing to stdout. Read through lots of manuals. But
> didn't find the way. Please help me.
> *Which one to use?
> curl_easy_recv ( CURL* curl, void* buffer, size_t buflen, size_t* n );
> (or)
> curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, callback_func);
Looks to me that CURLOPT_WRITEFUNCTION has a few advantages over curl_easy_recv:
1. You don't have to make the HTTP request yourself (curl_easy_recv only work if you sent CURLOPT_CONNECT_ONLY, which means that curl will establish the connection, but will not make any requests on that socket)
2. Your application will not "leak" data on stdout (if you don't set the WRITEFUNCTION, curl will output data to stdout regardless of any other settings). This is great for speed, security etc., etc.
3. You won't need to change much if you ever need to move to the multi interface.
> PS Why don't developers consider making function like curl_exec() in php?
With the default options, that would be curl_easy_perform()
However, I'm guessing you want the behavior of curl_exec() when CURLOPT_RETURNTRANSFER is set. You can't have different return values in C (see http://stackoverflow.com/questions/6009860/c-function-with-same-name-returning-different-data-values for instance). I believe it is possible in PHP because it is a weakly typed language, so when you write:
<? $a = curl_exec() ?>, the variable a will take the type returned by the function.
The closest thing you could have is a function like: char* curl_easy_perform2(), with the return value being NULL on error. I cannot speak for the core developers, but I would like to see such a patch submitted.
Regards,
Andrei
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-05-06