我正在尝试通过c ++中的套接字发送html;接受请求后,我的代码将调用以下函数将arr发送给客户端。当我使用c中的客户端代码在终端上对其进行测试时,我收到了arr。但是,当我尝试通过Web浏览器连接到端口时,我的代码显示连接成功并发送成功,但是在浏览器上未打印任何内容,它只是保持加载状态。为什么会这样?
void sendTCP(int client_socket, vector<string> path)
{
cout<<"in sendTCP\n";
//string web=conWeb(path);
//cout<<"constructed web is "<<web<<endl;
char arr[1024]="HTTP/1.1 200 OK\r\n\r\n<html>\n\r<body>\n\r\rhello\n\r</body>\n</html>";
int send_res=send(client_socket,arr,sizeof(arr),0);
if(send_res == -1)
{
perror("send");
}
else{
cout<<"send success\n";
}
}
也许尝试重组字符串
arr="HTTP/1.1 200 OK\nContent-Type:text/html\nContent-Length: 16\n\n<h1>testing</h1>"