June 26, 2018
to get get() from std.net.curl return a ubyte[] and use my http instance, all those failed:

string link = "http://...";
auto client = HTTP();
// set some client attributes...
auto fileContents = get!(AutoProtocol, ubyte)(link, client);
auto fileContents = get!(ubyte)(link, client);
auto fileContents = get!(client, ubyte)(link, client);

 I still didn't "get" D templates.
June 26, 2018
On 06/26/2018 10:37 AM, Rib wrote:
> to get get() from std.net.curl return a ubyte[] and use my http instance, all those failed:
> 
> string link = "http://...";
> auto client = HTTP();
> // set some client attributes...
> auto fileContents = get!(AutoProtocol, ubyte)(link, client);
> auto fileContents = get!(ubyte)(link, client);
> auto fileContents = get!(client, ubyte)(link, client);
> 
>   I still didn't "get" D templates.

This worked for me:


import std.net.curl;
import std.stdio;
import std.functional;

void myHeaderReceivingFunction(const(char[]) key, const(char[]) value) {
    writefln("Received header: %s = %s", key, value);
}

size_t myDataReceivingFunction(ubyte[] data) {
    writefln("Received data; first part: %s", data[0..10]);
    return data.length;
}

void main() {
    auto client = HTTP("http://dlang.org");

    // If you don't have an actual delegate, you can use std.functional.toDelegate:
    client.onReceiveHeader = (&myHeaderReceivingFunction).toDelegate;

    // ... or you can create a delegate with a lambda on the fly:
    client.onReceive = (ubyte[] data) { return myDataReceivingFunction(data); };

    client.perform();
}

Ali