Example #1
0
  private String doGet(String url, Map<String, String> param) throws WeiboException {

    HttpGet httpGet = new HttpGet();
    URIBuilder uriBuilder;
    try {
      uriBuilder = new URIBuilder(url);

      Set<String> keys = param.keySet();

      for (String key : keys) {
        String value = param.get(key);
        if (!TextUtils.isEmpty(value)) uriBuilder.addParameter(key, param.get(key));
      }

      httpGet.setURI(uriBuilder.build());

      AppLogger.d(uriBuilder.build().toString());

    } catch (URISyntaxException e) {
      AppLogger.d(e.getMessage());
    }

    CookieStore cookieStore = new BasicCookieStore();

    HttpContext localContext = new BasicHttpContext();
    localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

    HttpResponse response = getHttpResponse(httpGet, localContext);

    if (response != null) {
      return dealWithResponse(response);
    } else {
      return "";
    }
  }
Example #2
0
  /** don't need error message to show */
  private String doGetSaveFile(
      String url, String path, FileDownloaderHttpHelper.DownloadListener downloadListener) {

    URIBuilder uriBuilder;
    HttpGet httpGet = new HttpGet();
    try {
      uriBuilder = new URIBuilder(url);

      httpGet.setURI(uriBuilder.build());

      AppLogger.d(uriBuilder.build().toString());

    } catch (URISyntaxException e) {
      AppLogger.d(e.getMessage());
    }

    HttpResponse response = null;
    try {

      response = httpClient.execute(httpGet);

    } catch (ConnectTimeoutException ignored) {

      AppLogger.e(ignored.getMessage());

    } catch (ClientProtocolException ignored) {
      AppLogger.e(ignored.getMessage());

    } catch (IOException ignored) {
      AppLogger.e(ignored.getMessage());
    }

    if (response != null) {

      return FileDownloaderHttpHelper.saveFile(response, path, downloadListener);

    } else {
      return "";
    }
  }