码迷,mamicode.com
首页 > 编程语言 > 详细

JAVA_Socket_Get请求

时间:2014-12-04 09:59:11      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:blog   http   io   ar   os   java   on   div   log   

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请求

标签:blog   http   io   ar   os   java   on   div   log   

原文地址:http://www.cnblogs.com/SKeyC27/p/4142084.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!