我正在为我的班级制作一个HTTP服务器。但是,Firefox不会显示返回的文件。我构造了一个响应头并将其放在右边
content-length
对于我要发送的文件,然后我发送响应头并调用
send()
. 接下来我用
发送()
再次发送文件,为什么Firefox不显示文件?我将在下面发布相关代码。
error_response
,在404错误期间。使用实时http头,我可以看到Firefox接收到正确的响应头,并且
cout << error_response << endl;
打印正确的响应。为什么Firefox不显示它?我只需要给你打一个电话吗
发送()
// send response headers
response->Print( buffer, 2000 );
if ( send( acc_tcp_sock, buffer, sizeof(buffer), 0 ) < 0 ) {
cerr << "Unable to send response headers to client." << endl;
return 5;
}
// if 200 and GET then send file
if ( response->Get_code() == 200 && method == "GET" ) {
// send file
}
// close file, if it has been opened
if ( response->Get_code() == 200 ) {
fclose( returned_file );
}
else if ( method == "GET" ) {
if ( send( acc_tcp_sock, error_response.c_str(), error_response.length(), 0 ) < 0 ) {
cerr << "Unable to send data to client." << endl;
return 6;
}
cout << error_response << endl;
}
close( acc_tcp_sock ); // close the connection
}
return 0;
}