The HttpClient framework in Android sends a GET request

Source: Internet
Author: User

/** * The way to use httpclientget request *  * @param username * @param password * @return NULL indicates a problem with the path being evaluated, text returns the requested data */public Stati C string Httpclientget (string username, string password) {try {//1. Open a browser httpclient client = new Defaulthttpclient ();// 2. Enter the address string path = "Http://172.22.64.156:8080/0001AndroidWebService/LoginServlet?username=" + urlencoder.encode ( username) + "&password=" + urlencoder.encode (password);//Specify the request mode HttpGet get = new HttpGet (path);//3. Hit Enter HttpResponse Response = Client.execute (get);//Gets the returned code int code = Response.getstatusline (). Getstatuscode (); if (code = = 200) {// Gets the information returned inputstream is = Response.getentity (). getcontent (); String Text = Streamutil.readstream (is); return text;} else {return null;}} catch (Exception e) {e.printstacktrace (); return null;}}

The HttpClient framework in Android sends a GET request

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.