02-response Simple Response message

Source: Internet
Author: User

 PackageCom.day5;ImportJava.io.BufferedWriter;Importjava.io.IOException;ImportJava.io.OutputStream;ImportJava.io.OutputStreamWriter;ImportJava.net.ServerSocket;ImportJava.net.Socket;Importjava.util.Date; Public classServer {/**Liu Shihua Response response *@paramargs *@throwsException*/     Public Static voidMain (string[] args)throwsException {//Set line breakString CRLF = "\ r \ n"; //register for 8080 socketsServerSocket server=NewServerSocket (8080); System.out.println ("Start accepting requests ..."); //Accept client RequestsSocket socket =server.accept (); //get client Object output stream objectOutputStream out =Socket.getoutputstream (); //convert byte output stream to character output flowOutputStreamWriter writer =NewOutputStreamWriter (out); //convert character output to buffer character streamBufferedWriter BW =NewBufferedWriter (writer); StringBuilder Response=NewStringBuilder (); //Response message body contentString html= "; //Setting the response header informationResponse.append ("http/1.1-OK"). Append (CRLF); Response.append ("Server:apache/2.4.10 (WIN32) php/5.3.28"). Append (CRLF); Response.append ("Date:"). Append (NewDate ()). append (CRLF); Response.append ("Content-type:text/html"). Append (CRLF); Response.append ("Content-length:" +html.getbytes (). Length). append (CRLF);        Response.append (CRLF);                Response.append (HTML); //sending data to the clientBw.write (response.tostring ()); //Close Resource FlowBw.close ();        Socket.close ();                Server.close ();            SYSTEM.OUT.PRINTLN (response); }}

Response message Format

http/1.1 okserver:apache/2.4.10 (Win32) php/5.3.28Jul 2018 14:52:32 gmtcontent-type : text/htmlcontent-length:17

02-response Simple Response message

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.