Download file via http

Kai Meyer kai at
Tue Dec 13 09:58:57 PST 2011

On 12/13/2011 10:39 AM, Vladimir Panteleev wrote:
> On Tuesday, 13 December 2011 at 17:29:20 UTC, Kai Meyer wrote:
>> I get bytes_needed from the Content-Length header. The I get the
>> correct number of bytes from the Content-Length, bytes_needed gets the
>> right value, but the resulting file isn't right. The file has the
>> right number of bytes, but I appear to have an extra '0a' at the very
>> beginning of the file, but if I do 'ss.getchar()', to get rid of it, I
>> get an exception that there's not enough data in the stream.
> In an HTTP request, the headers are separated from the body by an empty
> line. Headers use CR/LF line endings, so the body is always preceded by
> a 0D 0A 0D 0A sequence. It looks like your code is not snipping the last
> 0A.
> Where did the getchar method come from? There is no mention of it in
> Phobos. Perhaps you could try the read(out ubyte) method?

Oh, I meant getc(), not getchar(), sorry. It looks like read(out ubyte) 
worked on windows.

I'm using ss.readLine() to pull headers from the stream. When the string 
returned from ss.readLine() is empty, then I move on to the stream. I'm 
going to be using this application on Windows, Linux, and Mac, which is 
why I chose D. This feels like I've just entered the newline/carriage 
return nightmare. Should I not be using readLine()? Or is there some 
generic code that will always work and stick me at the beginning of the 

-Kai Meyer

More information about the Digitalmars-d-learn mailing list