zoukankan      html  css  js  c++  java
  • 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;
    		}
    	}

    版权声明:本文博主原创文章。博客,未经同意不得转载。

  • 相关阅读:
    PHP程序员的40点陋习
    配置php.ini实现PHP文件上传功能
    PHP的线程安全与非线程安全版本的区别
    IIS下PHP的三种配置方式比较
    fir.im Weekly
    fir.im Weekly
    fir.im Weekly
    fir.im Weekly
    fir.im Weekly
    fir.im Weekly
  • 原文地址:https://www.cnblogs.com/gcczhongduan/p/4877570.html
Copyright © 2011-2022 走看看