Download file via http

Vladimir Panteleev vladimir at thecybershadow.net
Tue Dec 13 09:39:00 PST 2011


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?


More information about the Digitalmars-d-learn mailing list