Import Java.io.BufferedReader;
Import Java.io.InputStreamReader;
Import org.apache.http.HttpEntity;
Import Org.apache.http.HttpHost;
Import Org.apache.http.HttpResponse;
Import Org.apache.http.auth.AuthScope;
Import Org.apache.http.auth.UsernamePasswordCredentials;
Import Org.apache.http.client.methods.HttpGet;
Import Org.apache.http.conn.params.ConnRoutePNames;
Import org.apache.http.impl.client.DefaultHttpClient;
/**
* HttpClient 4.0 code example for accessing HTTPS via proxy.
*
* @author java Century Network (java2000.net, laozizhu.com)
*/
public class Httpsproxyget {
public static void Main (string[] args) throws Exception {
Defaulthttpclient httpclient = new Defaulthttpclient ();
Certified Data
I am here to write, please fill in the actual situation
Httpclient.getcredentialsprovider (). SetCredentials (New Authscope ("10.60.8.20", 8080),
New Usernamepasswordcredentials ("username", "password"));
Target sites, ports, and protocols to access
Httphost targethost = new Httphost ("www.google.com", 443, "https");
Settings for Agents
Httphost proxy = new Httphost ("10.60.8.20", 8080);
Httpclient.getparams (). Setparameter (Connroutepnames.default_proxy, PROXY);
Destination Address
HttpGet httpget = new HttpGet ("/adsense/login/zh_cn/?");
SYSTEM.OUT.PRINTLN ("Goal:" + targethost);
SYSTEM.OUT.PRINTLN ("Request:" + httpget.getrequestline ());
System.out.println ("Agent:" + proxy);
Perform
HttpResponse response = Httpclient.execute (Targethost, HttpGet);
httpentity entity = response.getentity ();
System.out.println ("----------------------------------------");
System.out.println (Response.getstatusline ());
if (entity!= null) {
System.out.println ("Response Content Length:" + entity.getcontentlength ());
}
Show results
BufferedReader reader = new BufferedReader (New InputStreamReader (Entity.getcontent (), "UTF-8"));
String line = null;
while (line = Reader.readline ())!= null) {
System.out.println (line);
}
if (entity!= null) {
Entity.consumecontent ();
}
}
}