package cn.dss.studay网络编程.mytomcat; import java.io.*; import java.net.Socket; /** * * 模拟客户端接收数据。 * * */ public class ClientDemo { public static void main(String[] args) throws IOException { Socket socket= new Socket("127.0.0.1",8080); // 向服务器端发送数据包 PrintWriter out= new PrintWriter(socket.getOutputStream(),true); out.println("GET /myweb/1.html HTTP/1.1"); out.println("Host: localhost:8080"); out.println("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"); out.println("Accept-Encoding: gzip, deflate, sdch "); out.println("Accept-Language: zh-CN,zh;q=0.8 "); out.println(); // 接收服务端发送的数据 InputStreamReader inputStreamReader = new InputStreamReader(socket.getInputStream()); char [] buf = new char[1024]; int read = inputStreamReader.read(buf); String s = new String(buf, 0, read); System.out.println(s); } }
java模仿浏览器的功能
最新推荐文章于 2024-06-23 12:04:59 发布