- 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协议加上什么才能收到响应和网页 |