标签:asn html baidu sys must pre soc www 访问
1 由于(https://www.cnblogs.com/S-Mustard/p/11924227.html)讲到通过telnet访问百度首页,现在通过java代码来实现访问百度服务,获取首页信息。
try(Socket s=new Socket("www.baidu.com",80); Scanner in =new Scanner(s.getInputStream(),"UTF-8"); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));){ StringBuffer sb = new StringBuffer(); sb.append("GET https://www.baidu.com HTTP/1.1\r\n").append("Host:"+ "www.baidu.com" + "\r\n").append("\r\n"); out.write(sb.toString()); out.flush(); while(in.hasNextLine()){ System.out.println(in.nextLine()); } }
标签:asn html baidu sys must pre soc www 访问
原文地址:https://www.cnblogs.com/S-Mustard/p/11938744.html