CURL: Save response to string
simendsjo
simendsjo at gmail.com
Sat Jun 30 14:54:04 PDT 2012
On Sat, 30 Jun 2012 23:49:51 +0200, Nrgyzer <nrgyzer at gmail.com> wrote:
> Hi guys,
>
> I know... there's a lib for curl but I'm using an old CURL-binding for
> D... I've the following problem: I'm sending my login data to
> a web page and I want store the response of curl_easy_perform() in a
> string. So I'm using the following few lines to do that:
>
> string temp;
>
> size_t callback(char* ptr, size_t size, size_t, nmemb, string* stream) {
> temp ~= *ptr;
> // or: How can I append ptr to my stream?
> // When I use '*stream ~= cast(char) ptr;' I get an memory
> violation...
> }
>
Wild guess without knowing curl:
temp ~= *ptr; will add the first character of ptr to temp.
Is ptr zero terminated?
You can convert a pointer to an array by using the slice syntax:
temp ~= ptr[0..size]; // assuming size is the number of elements in ptr
More information about the Digitalmars-d-learn
mailing list