HttpClient类是一个简单的HTTP客户端程序,它已GET方式向HTTP服务器发送HTTP请求 package com.http; import java.io.IOException; import java.io.OutputStream; import java.net.Socket; public class HTTPClient { public static void main(String[] args) { String uri="index.htm";//请求HTTP的请求uri if(args.length!=0)uri=args[0]; doGet("localhost",8080,uri); //按照GET请求方式访问HTTPServer } private static void doGet(String host, int port, String uri) { // TODO Auto-generated method stub Socket socket=null; try{ socket=new Socket(host,port); //与HTTPserver建立TCP连接 StringBuffer sb=new StringBuffer("GET"+uri+" HTTP/1.1\r\n");//HTTP请求的一行 //发送HTTP请求