The HTTP header is separated from the data by a blank line. The blank line is a CR/LF pair. Note however that each non-blank line in the header will be terminated by CR/LF. Your code looks for the first CR/LF pair which occurs at the end of the first line in the header. You need to look for two CR/LF pairs in a row.