如题,见附件
commons-codec-1.3.jar
commons-httpclient-3.1-alpha1.jar
commons-logging-1.1.1.jar
commons-codec-1.3.jar
commons-httpclient-3.1-alpha1.jar
commons-logging-1.1.1.jar
package dj.uri;
import java.io.IOException;
import java.net.*;
import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
public class Test {
/**
* @param args
* @throws URISyntaxException
* @throws IOException
* @throws HttpException
*/
public static void main(String[] args) throws URISyntaxException, HttpException, IOException {
HttpClient client = new HttpClient();
GetMethod getMethod = new GetMethod("http://www.baidu.com/");
//设置成了默认的恢复策略,在发生异常时候将自动重试3次,在这里你也可以设置成自定义的恢复策略
getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler());
System.out.println(getMethod.getResponseCharSet());
//执行getMethod
int statusCode = client.executeMethod(getMethod);
if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: " + getMethod.getStatusLine());
}
byte[] responseBody = getMethod.getResponseBody();
System.out.println(new String(responseBody,getMethod.getResponseCharSet()));
getMethod.releaseConnection();
}
}