On 11/14/2013 11:43 AM, Dicebot wrote:
On Thursday, 14 November 2013 at 19:41:13 UTC, Agustin wrote:
I'm trying to use http://dlang.org/phobos/std_net_curl.html and when i
compile the same example i get:

cannot implicitly convert expression (get(cast(const(char)[])address,
AutoProtocol())) of type char[] to string

string address = "http://dlang.org";;
string _data = get(address);

`get` returns mutable data, one should respect it:

char[] data = get(address); // or just use `auto data = `

However, that data can automatically be converted to string if get() were pure. (I can understand how such a function cannot be.)

A simple wrapper:

import std.net.curl;
import std.exception;

string getAsString(string address)
{
    auto result = get(address);
    return assumeUnique(result);
}

void main()
{
    string content = getAsString("dlang.org");
}

Ali

Reply via email to