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

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

 更新時(shí)間:2013年10月15日 16:52:20   作者:  
這篇文章介紹了Android 中HttpURLConnection與HttpClient使用的簡(jiǎn)單實(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)文章

最新評(píng)論

仪征市| 延庆县| 都昌县| 金山区| 常德市| 滕州市| 祁连县| 瑞安市| 义马市| 汉川市| 福泉市| 澄江县| 岑巩县| 抚顺县| 石狮市| 象山县| 抚远县| 柳林县| 新乡市| 丹巴县| 清新县| 云梦县| 宁都县| 敖汉旗| 西吉县| 玉溪市| 卢氏县| 建德市| 庆城县| 道孚县| 枞阳县| 凉山| 岚皋县| 岑溪市| 当涂县| 托里县| 双流县| 锦州市| 永川市| 鄂托克旗| 永仁县|