Re: libCurl in C

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Words by Jai Sharma [Wed, Jan 21, 2009 at 02:13:04AM +0530]:
> Dear Friends,
> 
> I am using CURL to get HTTP response.
> The default output for CURL is stdout, but i am unable to change it to
> a variable.
> 
> Right now,
> I am using a temporary file for this purpose and read it to process it.
> Is there any way, by which method i will get CURL output to a string
> or any structure?
> 

I usually do:

/* store curl "output" here */
char buffer[BUFFER_SIZE];

/* function that does the copy */
size_t tobuffer(char *ptr, size_t size, size_t nmemb, void *stream)
{
	strncpy(buffer,ptr,size*nmemb);
	return size*nmemb;
}

....
/* tell curl to use the upper function */
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &tobuffer);
....

then do whatever I want (print, parse, etc) with buffer.

-- 
Jose Celestino | http://japc.uncovering.org/files/japc-pgpkey.asc
----------------------------------------------------------------
"One man’s theology is another man’s belly laugh." -- Robert A. Heinlein
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Assembler]     [Git]     [Kernel List]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [C Programming]     [Yosemite Campsites]     [Yosemite News]     [GCC Help]

  Powered by Linux