Remove http header in socket C

1

I made a socket in C. This program is operated by command line and compiled on Linux. It receives as a parameter a complete URI and a filename, and then connects to the server, retrieves the page and saves it to the reported file. After getting the remote data. The file received by the recv function comes with a HEADER. The question is: How to remove this HEADER before the file is written by the fwrite () function.

    
asked by anonymous 15.06.2015 / 16:45

1 answer

1

Do not start writing the final file before the header ends

int headerterminado = 0;
char *p = NULL;
while (recv(socket, buffer, ...)) {
    p = strstr(buffer, "\r\n\r\n");
    if (p) headerterminado = 1;
}

'Of course you have to be aware of the fact that "\r\n\r\n" is split by 2% with% s.

    
15.06.2015 / 20:27