Android Settings agent (verify user name and password)

Source: Internet
Author: User

These days in the study in the Android, parsing the Web page, but the company content, link outside the network needs agents, and need to verify the user name and password, very headache, online check the next, no clue, finally in a foreign blog to see similar, recorded

URL url = new URL (urlstring);    string Host=android.net.proxy.getdefaulthost ();    int Port=android.net.proxy.getdefaultport ();        socketaddress Address=null;    try {    address=new inetsocketaddress (host, port);    } catch (Exception e) {    system.out.println (E.getmessage ());    }         proxy proxy=new Java.net.Proxy (Java.net.Proxy.Type.HTTP, address);    string credentials = "z10127:[email protected]";    byte[] Toencode = null;    try {       Toencode = credentials.getbytes ("UTF-8");     } catch (Unsupportedencodingexception E1) {       e1.printstacktrace ();     }    HttpURLConnection  ucon=null;        try {     ucon = (httpurlconnection) url.openconnection (proxy);     ucon.setconnecttimeout (50000);

Ucon.setrequestproperty ("Proxy-authorization", "Basic" + base64.encodetostring (Toencode, Base64.default));

Ucon.connect ();    } catch (Exception e) {e.printstacktrace (); }

Ucon.connect ();     int responsecode = Ucon.getresponsecode ();           InputStream Instr=null;           if (Responsecode = = HTTPURLCONNECTION.HTTP_OK) {instr = Ucon.getinputstream ();    } Bufferedinputstream bis = new Bufferedinputstream (instr);    Bytearraybuffer BAF = new Bytearraybuffer (1024);    int current = 0; while (current = Bis.read ())! =-1) {//BAF:     Append (New String (Baf,0,current, "UTF-8"));    Baf.append ((byte) current);    } instr.close ();    Bis.close ();    Ucon.disconnect (); Return encodingutils.getstring (Baf.tobytearray (), "gb2312");

Android Settings agent (verify user name and password)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.