cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: An example of using libcurl to load a URL via http in a c++ program?

From: Tim Tassonis <timtas_at_cubic.ch>
Date: Sat, 14 Jul 2007 02:35:15 +0200

ying lcs wrote:
> On 7/11/07, Dan Fandrich <dan_at_coneharvesters.com> wrote:
>> On Wed, Jul 11, 2007 at 04:22:28PM -0500, ying lcs wrote:
>> > Can you please tell me where I can find an example of using libcurl to
>> > load a URL via http in a c++ program?
>> >
>> > I have looked here, but i can't find what I am looking for.
>>
>> All the examples in the doc/examples/ directory of the source archive
>> should be valid C++ (they're written in the "ANSI C" subset of C++).
>> If you
>> want examples using the curlpp binding to libcurl, try looking at the
>> curlpp source (see http://curl.haxx.se/libcurl/cplusplus/).
>>
>
> Thanks. I have looked at the htmltidy.c as my example since I want to
> do a http get:
> My question is how can I setup curl to go via http cache server
> (squid) when it loads the url using http get?

How about this curl_easy_setopt option:
CURLOPT_PROXY

Set HTTP proxy to use. The parameter should be a char * to a zero
terminated string holding the host name or dotted IP address.

In your example:

curl_easy_setopt(curl, CURLOPT_PROXY, "http://youd.squid.server");

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

Bye
Tim

>
>
> CURL *curl;
> char curl_errbuf[CURL_ERROR_SIZE];
> TidyDoc tdoc;
> TidyBuffer docbuf = {0};
> TidyBuffer tidy_errbuf = {0};
> int err;
> if ( argc == 2) {
> curl = curl_easy_init();
> curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
> curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errbuf);
> curl_easy_setopt(curl, CURLOPT_NOPROGRESS, no);
> curl_easy_setopt(curl, CURLOPT_VERBOSE, yes);
> curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb);
>
>
>
> curl_easy_setopt(curl, CURLOPT_WRITEDATA, &docbuf);
> err=curl_easy_perform(curl);
>
> }
>
>
>> >>> Dan
>> --
>> http://www.MoveAnnouncer.com The web change of address
>> service
>> Let webmasters know that your web site has moved
>>
Received on 2007-07-14