lundi 28 décembre 2020

How to send HTTP header and HTTP body separately using socket?

I can send both header and body this way,

std::string complete_response = "HTTP/1.1 200 OK\r\nContent-Length: 13\r\nConnection: close\r\n\r\nHello, world!";

socket.send(complete_response);

But I'm lost when it comes to sending them at separate stages. I've attempted the following and it doesn't seem working at all,

std::string header = "HTTP/1.1 200 OK\r\nContent-Length: 13\r\nConnection: close\r\n\r\n";
std:string body =  "Hello, world!";

socket.send(header);
socket.send(body);

Using Wireshark, I see that the browser get the header part then browser close the connection and not wait for the body.

Aucun commentaire:

Enregistrer un commentaire