Tag: Log print uses the type to verify the Encode base add password
Public Static voidMain (string[] args) {//TODO auto-generated Method Stub Try{URL URL=NewURL ("http://www.baidu.com"); //creating a proxy serverInetsocketaddress addr =NewInetsocketaddress ("172.21.1.8", 80); Proxy proxy=NewProxy (Proxy.Type.HTTP, addr);//HTTP ProxyURLConnection conn =url.openconnection (proxy); //The following three lines are required to enter your account password information when you need to verifyString Headerkey = "Proxy-authorization"; String Headervalue= "Basic" +base64.encodetostring ("Atco:atco". GetBytes (),false);//account password by: Separate, base64 encryption methodConn.setrequestproperty (Headerkey, Headervalue); InputStream in=Conn.getinputstream (); //InputStream in = Url.openstream (); String s = ioutils.tostring (in, "Utf-8"); System.out.println (s); } Catch(Exception e) {e.printstacktrace (); } }
Using Proxy in JAVA HTTP connection (httpurlconnection) and its validation (authentication)