首页 > 代码库 > JAVA_Socket_Get请求
JAVA_Socket_Get请求
import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.IOException;import java.io.InputStreamReader;import java.io.OutputStreamWriter;import java.net.Socket;import java.net.UnknownHostException;public class TestMain{ /** * @param args */ public static void main(String[] args) { //http://hk.cmbchina.com/WebAffair/?pageid=Webterms try { String host = "hk.cmbchina.com"; Socket socket = new Socket(host, 80); // 这些是必须的 StringBuffer head = new StringBuffer(); head.append("GET " +"/WebAffair/?pageid=Webterms"+ "/ HTTP/1.1" + "\r\n"); head.append("Host:" + host + "\r\n" + "\r\n"); BufferedReader in = new BufferedReader(new InputStreamReader( socket.getInputStream())); BufferedWriter out = new BufferedWriter(new OutputStreamWriter( socket.getOutputStream())); out.append(head.toString()); out.flush(); //测试输出
System.out.println(in.readLine()); System.out.println(in.readLine()); System.out.println(in.readLine()); System.out.println(in.readLine()); System.out.println(in.readLine()); System.out.println(in.readLine()); System.out.println(in.readLine()); System.out.println(in.readLine()); System.out.println(in.readLine()); System.out.println(in.readLine()); System.out.println(in.readLine()); System.out.println(in.readLine()); System.out.println(in.readLine()); System.out.println(in.readLine()); System.out.println(in.readLine()); System.out.println(in.readLine()); System.out.println(in.readLine()); System.out.println(in.readLine()); System.out.println(in.readLine()); System.out.println(in.readLine()); System.out.println(in.readLine()); System.out.println(in.readLine()); System.out.println(in.readLine()); System.out.println(in.readLine()); System.out.println(in.readLine()); System.out.println(in.readLine()); System.out.println(in.readLine()); System.out.println(in.readLine()); System.out.println(in.readLine()); System.out.println(in.readLine()); System.out.println(in.readLine()); System.out.println(in.readLine()); } catch (UnknownHostException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } return; }}
JAVA_Socket_Get请求
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。