cz.msebera.android.httpclient.impl.client.DefaultHttpClient Java Examples

The following examples show how to use cz.msebera.android.httpclient.impl.client.DefaultHttpClient. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NetWorkTool.java    From FoodOrdering with Apache License 2.0 6 votes vote down vote up
public static String getContent(String url) throws Exception {
    StringBuilder sb = new StringBuilder();

    HttpClient client = new DefaultHttpClient();
    HttpParams httpParams = (HttpParams) client.getParams();
    // 设置网络超时参数
    HttpConnectionParams.setConnectionTimeout(httpParams, 3000);
    HttpConnectionParams.setSoTimeout(httpParams, 5000);
    HttpResponse response = client.execute(new HttpGet(url));
    HttpEntity entity = response.getEntity();
    if (entity != null) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                entity.getContent(), "GBK"), 8192);
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line);
        }
        reader.close();
    }
    return sb.toString();
}
 
Example #2
Source File: FeedFragment.java    From Instagram-Profile-Downloader with MIT License 5 votes vote down vote up
@Override
protected String doInBackground(Void... params) {
    HttpClient httpClient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(url);
    try {
        HttpResponse response = httpClient.execute(httpGet);
        HttpEntity httpEntity = response.getEntity();
        return EntityUtils.toString(httpEntity);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #3
Source File: ProfileFragment.java    From Instagram-Profile-Downloader with MIT License 5 votes vote down vote up
@Override
protected String doInBackground(Void... params) {
    HttpClient httpClient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(url);
    try {
        HttpResponse response = httpClient.execute(httpGet);
        HttpEntity httpEntity = response.getEntity();
        return EntityUtils.toString(httpEntity);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #4
Source File: OverviewDialog.java    From Instagram-Profile-Downloader with MIT License 5 votes vote down vote up
@Override
protected String doInBackground(Void... params) {
    HttpClient httpClient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(url);
    try {
        HttpResponse response = httpClient.execute(httpGet);
        HttpEntity httpEntity = response.getEntity();
        return EntityUtils.toString(httpEntity);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #5
Source File: MainActivity.java    From Instagram-Profile-Downloader with MIT License 5 votes vote down vote up
@Override
protected String doInBackground(Void... params) {
    HttpClient httpClient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(url);
    try {
        HttpResponse response = httpClient.execute(httpGet);
        HttpEntity httpEntity = response.getEntity();
        return EntityUtils.toString(httpEntity);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #6
Source File: MainActivity.java    From Instagram-Profile-Downloader with MIT License 5 votes vote down vote up
@Override
protected String doInBackground(Void... params) {
    HttpClient httpClient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(final_url);
    try {
        HttpResponse response = httpClient.execute(httpGet);
        HttpEntity httpEntity = response.getEntity();
        return EntityUtils.toString(httpEntity);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #7
Source File: IntroScreenActivity.java    From Instagram-Profile-Downloader with MIT License 5 votes vote down vote up
@Override
protected String doInBackground(Void... params) {
    HttpClient httpClient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(getResources().getString(R.string.get_user_info_url) + token);
    try {
        HttpResponse response = httpClient.execute(httpGet);
        HttpEntity httpEntity = response.getEntity();
        return EntityUtils.toString(httpEntity);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #8
Source File: DownloadProfileImageActivity.java    From Instagram-Profile-Downloader with MIT License 5 votes vote down vote up
@Override
protected String doInBackground(Void... params) {
    HttpClient httpClient = new DefaultHttpClient();
    try {
        HttpGet httpGet = new HttpGet(url);
        HttpResponse response = httpClient.execute(httpGet);
        HttpEntity httpEntity = response.getEntity();
        return EntityUtils.toString(httpEntity);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #9
Source File: HttpUtils.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
public static String getResponseFromGetUrl(String url,
                                               String params) throws Exception {
        Log.d("Chen", "url--" + url);
        if (null != params && !"".equals(params)) {

            url = url + "?";

            String[] paramarray = params.split(",");

            for (int index = 0; null != paramarray && index < paramarray.length; index++) {

                if (index == 0) {

                    url = url + paramarray[index];
                } else {

                    url = url + "&" + paramarray[index];
                }

            }

        }

        HttpGet httpRequest = new HttpGet(url);

//        httpRequest.addHeader("Cookie", logininfo);

        HttpParams httpParameters = new BasicHttpParams();
        // Set the timeout in milliseconds until a connection is established.
        int timeoutConnection = 30000;
        HttpConnectionParams.setConnectionTimeout(httpParameters,
                timeoutConnection);
        // Set the default socket timeout (SO_TIMEOUT)
        // in milliseconds which is the timeout for waiting for data.
        int timeoutSocket = 30000;
        HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
        DefaultHttpClient httpclient = new DefaultHttpClient(httpParameters);

        // DefaultHttpClient httpclient = new DefaultHttpClient();
        StringBuffer sb = new StringBuffer();


        try {
            HttpResponse httpResponse = httpclient.execute(httpRequest);

            String inputLine = "";
            // Log.d("Chen","httpResponse.getStatusLine().getStatusCode()"+httpResponse.getStatusLine().getStatusCode());
            if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {

                InputStreamReader is = new InputStreamReader(httpResponse
                        .getEntity().getContent());
                BufferedReader in = new BufferedReader(is);
                while ((inputLine = in.readLine()) != null) {

                    sb.append(inputLine);
                }

                in.close();

            } else if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_MODIFIED) {
                return "";
            }
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        } finally {
            httpclient.getConnectionManager().shutdown();
        }

        return sb.toString();

    }