Trouble sending HTTP response with Java Socket

前端 未结 4 1613
伪装坚强ぢ
伪装坚强ぢ 2021-01-14 00:55

I\'ve been trying to write the beginnings of a simple web server, but can\'t seem to get the response to get sent. I\'ve tried every type of Output stream imaginable but no

4条回答
  •  無奈伤痛
    2021-01-14 01:42

    Try pass the date.

     String res = "HTTP/1.0 200 OK\n"
             + "Server: HTTP server/0.1\n";
             + "Date: "+format.format(new java.util.Date())+"\n"; 
       + "Content-type: text/html; charset=UTF-8\n"; 
             + "Content-Length: 38\n\n";
             + "OK";
    out.write(res.getBytes());
    out.flush();
    
    private SimpleDateFormat format = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:Ss z");
    

提交回复
热议问题