www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - etc.c.curl...?

reply simendsjo <simendsjo gmail.com> writes:
Anyone using this module?
For a complete curl newbie, it's far from simple.. The names have 
changed, and are inconsistent. Is it CurlOpt.write_function or 
CurlOpt.writefunction? CurlOpt.connect_only or CurlOpt.connectonly?

I'm having a hard time finding any tutorials on libcurl. Or rather... 
I'm having a hard time finding example code on doing the most elementary 
task: Get a html page as a string! :|

The simplest c example shows how to do this in 4 lines, but not how to 
get the actual result! Where is the page I just downloaded?

     auto curl = curl_easy_init();
     assert(curl);
     scope(exit) curl_easy_cleanup(curl);

     curl_easy_setopt(curl, CurlOption.url, toStringz(url));
     assert(curl_easy_perform(curl) == 0);

And now..?
Jan 10 2012
next sibling parent Jimmy Cao <jcao219 gmail.com> writes:
--f46d04426740d747ff04b633a7fe
Content-Type: text/plain; charset=ISO-8859-1

There's a wrapper for it that will be included in Phobos.  This wrapper is
easier to work with for D.

It has  structs for HTTP, FTP and SMTP.

https://github.com/jcd/phobos/blob/curl-wrapper/etc/curl.d

2012/1/10 simendsjo <simendsjo gmail.com>

 Anyone using this module?
 For a complete curl newbie, it's far from simple.. The names have changed,
 and are inconsistent. Is it CurlOpt.write_function or
 CurlOpt.writefunction? CurlOpt.connect_only or CurlOpt.connectonly?

 I'm having a hard time finding any tutorials on libcurl. Or rather... I'm
 having a hard time finding example code on doing the most elementary task:
 Get a html page as a string! :|

 The simplest c example shows how to do this in 4 lines, but not how to get
 the actual result! Where is the page I just downloaded?

    auto curl = curl_easy_init();
    assert(curl);
    scope(exit) curl_easy_cleanup(curl);

    curl_easy_setopt(curl, CurlOption.url, toStringz(url));
    assert(curl_easy_perform(curl) == 0);

 And now..?

--f46d04426740d747ff04b633a7fe Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable There&#39;s a wrapper for it that will be included in Phobos. =A0This wrapp= er is easier to work with for D.<div><div><br></div><div>It has =A0structs = for HTTP, FTP and SMTP.</div><div><br></div><div><a href=3D"https://github.= com/jcd/phobos/blob/curl-wrapper/etc/curl.d">https://github.com/jcd/phobos/= blob/curl-wrapper/etc/curl.d</a><br> <div><br><div class=3D"gmail_quote">2012/1/10 simendsjo <span dir=3D"ltr">&= lt;<a href=3D"mailto:simendsjo gmail.com">simendsjo gmail.com</a>&gt;</span=
<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-le=

Anyone using this module?<br> For a complete curl newbie, it&#39;s far from simple.. The names have chang= ed, and are inconsistent. Is it CurlOpt.write_function or CurlOpt.writefunc= tion? CurlOpt.connect_only or CurlOpt.connectonly?<br> <br> I&#39;m having a hard time finding any tutorials on libcurl. Or rather... I= &#39;m having a hard time finding example code on doing the most elementary= task: Get a html page as a string! :|<br> <br> The simplest c example shows how to do this in 4 lines, but not how to get = the actual result! Where is the page I just downloaded?<br> <br> =A0 =A0auto curl =3D curl_easy_init();<br> =A0 =A0assert(curl);<br> =A0 =A0scope(exit) curl_easy_cleanup(curl);<br> <br> =A0 =A0curl_easy_setopt(curl, CurlOption.url, toStringz(url));<br> =A0 =A0assert(curl_easy_perform(curl) =3D=3D 0);<br> <br> And now..?<br> </blockquote></div><br></div></div></div> --f46d04426740d747ff04b633a7fe--
Jan 10 2012
prev sibling parent "Jonathan M Davis" <jmdavisProg gmx.com> writes:
On Tuesday, January 10, 2012 16:01:01 Jimmy Cao wrote:
 There's a wrapper for it that will be included in Phobos. This wrapper is
 easier to work with for D.
 
 It has structs for HTTP, FTP and SMTP.
 
 https://github.com/jcd/phobos/blob/curl-wrapper/etc/curl.d

Yeah. That would be the better route. etc.c.curl is basically just bindings to the C library, so for the most part, any usability issues originate with libcurl, and it's libcurl documentation that you'll need in order to figure out to use it. But the idea is that you'd use a D wrapper with a much friendlier API. The one above has been voted into Phobos but hasn't been merged in yet (and may end up with some minor tweaks before it does, but what's in that repository should be essentially what's going to be merged in for either 2.058 or 2.059 - depending on how soon a pull request for it is generated and how long it takes for it to actually be merged in). - Jonathan M Davis
Jan 10 2012