Android sends get requests to HTTP

Source: Internet
Author: User

/*** Get Request Method ** @ param username * @ param password * @ return null indicates that the obtained path is incorrect, text returns the request data */public static String getRequest (String username, String password) {try {String path = "http: // 172.22.64.156: 8080/0001 AndroidWebService/LoginServlet? Username = "+ URLEncoder. encode (username) + "& password =" + URLEncoder. encode (password); URL url = new URL (path); HttpURLConnection conn = (HttpURLConnection) url. openConnection (); conn. setreadtimeouts (500); conn. setRequestMethod ("GET"); int code = conn. getResponseCode (); if (code = 200) {// The request is successful. InputStream is = conn. getInputStream (); String text = StreamUtil. readStream (is); return text;} else {// return null for request failure;} catch (Exception e) {e. printStackTrace ();} return null ;}

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.