linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jose Celestino <japc@co.sapo.pt>
To: Jai Sharma <jai.unix@gmail.com>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: libCurl in C
Date: Tue, 20 Jan 2009 21:10:32 +0000	[thread overview]
Message-ID: <20090120211032.GA4752@co.sapo.pt> (raw)
In-Reply-To: <1f714d50901201243v289c2e84o19c79adfd0ef463d@mail.gmail.com>

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@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

      parent reply	other threads:[~2009-01-20 21:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-20 20:43 libCurl in C Jai Sharma
2009-01-20 20:52 ` Fabian Ischia
2009-01-20 21:10 ` Jose Celestino [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090120211032.GA4752@co.sapo.pt \
    --to=japc@co.sapo.pt \
    --cc=jai.unix@gmail.com \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).