最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android 中HttpURLConnection與HttpClient使用的簡單實(shí)例

 更新時(shí)間:2013年10月15日 16:52:20   作者:  
這篇文章介紹了Android 中HttpURLConnection與HttpClient使用的簡單實(shí)例,有需要的朋友可以參考一下

1:HttpHelper.java

復(fù)制代碼 代碼如下:

public class HttpHelper {
    //1:標(biāo)準(zhǔn)的Java接口
    public static String getStringFromNet1(String param){
        String result="";
        try{
            URL url=new URL(param);
            HttpURLConnection conn=(HttpURLConnection)url.openConnection();
            if(conn.getResponseCode()==HttpURLConnection.HTTP_OK){
                InputStream is=conn.getInputStream();
                byte[]data=new byte[1024];
                int len=is.read(data);
                result=new String(data,0,len);
                is.close();
                conn.disconnect();
            }
        }catch(Exception e){
            e.printStackTrace();
        }
        return result;
    }

    //2:Apache接口
    public static String getStringFromNet2(String param){
        String result="";
        try{
            HttpClient client=new DefaultHttpClient();
            HttpGet get=new HttpGet(param);
            HttpResponse response=client.execute(get);
            if(response.getStatusLine().getStatusCode()==HttpStatus.SC_OK){
                result=EntityUtils.toString(response.getEntity());
            }
        }catch(Exception e){
            e.printStackTrace();
        }
        return result;
    }
}

相關(guān)文章

最新評論

阳东县| 枝江市| 瓦房店市| 莫力| 乌拉特前旗| 渭南市| 军事| 刚察县| 集安市| 曲阳县| 定州市| 宁河县| 玉树县| 噶尔县| 盐边县| 洛宁县| 万宁市| 射阳县| 永和县| 扶风县| 全南县| 阜康市| 宜黄县| 临城县| 阳山县| 廊坊市| 古蔺县| 辽阳县| 盈江县| 鸡东县| 墨脱县| 龙井市| 甘谷县| 通辽市| 雅江县| 阿尔山市| 射洪县| 武邑县| 伊川县| 贞丰县| 通辽市|