Android中间httpclient发送帧get求
/** * 採用httpclientGet请求的方式 * * @param username * @param password * @return null表示求得的路径有问题,text返回请求得到的数据 */ public static String httpclientGet(String username, String password) { try { // 1.打开一个浏览器 HttpClient client = new DefaultHttpClient(); // 2.输入地址 String path = "http://172.22.64.156:8080/0001AndroidWebService/LoginServlet?username=" + URLEncoder.encode(username) + "&password=" + URLEncoder.encode(password); // 指定请求方式 HttpGet get = new HttpGet(path); // 3.敲回车 HttpResponse response = client.execute(get); //获取返回的码 int code = response.getStatusLine().getStatusCode(); if (code == 200) { //获取返回的信息 InputStream is = response.getEntity().getContent(); String text = StreamUtil.readStream(is); return text; } else { return null; } } catch (Exception e) { e.printStackTrace(); return null; } }
版权声明:本文博主原创文章。博客,未经同意不得转载。
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步