当前位置: 移动技术网 > IT编程>移动开发>Android > Android 中HttpURLConnection与HttpClient使用的简单实例

Android 中HttpURLConnection与HttpClient使用的简单实例

2019年07月24日  | 移动技术网IT编程  | 我要评论

广东街头现巨乳雕像,白领职业装,美女图片吧

1:httphelper.java

复制代码 代码如下:

public class httphelper {
    //1:标准的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;
    }
}

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网