小编Lya*_*oze的帖子

Android - HTTP GET请求

我开发了一个明确有效的HTTP GET方法.

public class GetMethodEx {


public String getInternetData() throws Exception{

        new TrustAllManager();
        new TrustAllSSLSocketFactory();

        BufferedReader in = null;
        String data = null;


        try
        {
            HttpClient client = new DefaultHttpClient();
            URI website = new URI("https://server.com:8443/Timesheets/ping");
            HttpGet request = new HttpGet();
            request.setURI(website);
            HttpResponse response = client.execute(request);
            response.getStatusLine().getStatusCode();

            in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
            StringBuffer sb = new StringBuffer("");
            String l = "";
            String nl = System.getProperty("line.separator");
            while ((l = in.readLine()) !=null){
                sb.append(l + nl);
            }
            in.close();
            data = sb.toString();
            return data;        
        } …
Run Code Online (Sandbox Code Playgroud)

https android get http

10
推荐指数
2
解决办法
7万
查看次数

标签 统计

android ×1

get ×1

http ×1

https ×1