import java.io.IOException;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;
/**
*
* @author jiawu,jiang
*
*/
public class Httpclient {
private static String url ="
/**
* @param args
*/
public static void main(String[] args) {
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod(url);
//代理的用戶名和密碼
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("", "");
//代理服務(wù)器
//client.getState().setCredentials( new AuthScope("192.168.0.254",3128),creds);
client.getState().setProxyCredentials(AuthScope.ANY, creds);
HostConfiguration hcf =new HostConfiguration ();
hcf.setProxy("192.168.0.254",3128);
//method.setDoAuthentication( true );
try {
int statusCode = client.executeMethod(hcf,method);
System.out.println("");
if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: " + method.getStatusLine());
}
byte[] responseBody = method.getResponseBody();
System.out.println(new String(responseBody));
} catch (HttpException e) {
System.err.println("Fatal protocol violation: " + e.getMessage());
e.printStackTrace();
} catch (IOException e) {
System.err.println("Fatal transport error: " + e.getMessage());
e.printStackTrace();
} finally {
method.releaseConnection();
}
}
}