黑马程序员技术交流社区
标题:
自己写web服务器问题
[打印本页]
作者:
王家胜
时间:
2013-12-7 20:34
标题:
自己写web服务器问题
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Date;
public class Server
{
public static void main(String[] args) throws Exception
{
ServerSocket ss=new ServerSocket(8080);
while(true)
{
Socket s=ss.accept();
PrintWriter pw=new PrintWriter(s.getOutputStream(),true);
pw.write("HTTP/1.1 200 OK");
pw.write("\n");
pw.write("Date: Sat, "+new Date());
pw.write("\n");
pw.write("Content-Type: text/html");
pw.write("\n");
pw.write("Transfer-Encoding: chunked");
pw.write("\n");
pw.write("Connection: Keep-Alive");
pw.write("\n");
pw.write("Cache-Control: private");
pw.write("\n");
pw.write("Expires: Sat, "+new Date());
pw.write("\n");
pw.write("Content-Encoding: gzip");
pw.write("\n");
pw.write("Server: BWS/1.1");
pw.write("\n");
pw.write("BDPAGETYPE: 2");
pw.write("\n");
pw.write("BDQID: 0x7e993e877ffa9331");
pw.write("\n");
pw.write("BDUSERID: 776849233");
pw.write("\n");
pw.write("Set-Cookie: BDSVRTM=106; path=/\rH_PS_PSSID=4301_1450_4211_4261_4451; path=/; domain="+s.getLocalAddress());
pw.write("\n");
pw.write("\n");
pw.write("<html>");
pw.write("<font color='red'>sucess</font>");
pw.write("</html>");
pw.flush();
pw.close();
s.close();
}
}
}
复制代码
收不到响应带码http协议加上什么才能收到响应和网页
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2