當前位置: 首頁>>代碼示例>>Java>>正文


Java DefaultHttpClient類代碼示例

本文整理匯總了Java中org.apache.http.impl.client.DefaultHttpClient的典型用法代碼示例。如果您正苦於以下問題:Java DefaultHttpClient類的具體用法?Java DefaultHttpClient怎麽用?Java DefaultHttpClient使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DefaultHttpClient類屬於org.apache.http.impl.client包,在下文中一共展示了DefaultHttpClient類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getNewHttpClient

import org.apache.http.impl.client.DefaultHttpClient; //導入依賴的package包/類
private static HttpClient getNewHttpClient() { 
   try { 
       KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); 
       trustStore.load(null, null); 

       SSLSocketFactory sf = new SSLSocketFactoryEx(trustStore); 
       sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); 

       HttpParams params = new BasicHttpParams(); 
       HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); 
       HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); 

       SchemeRegistry registry = new SchemeRegistry(); 
       registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); 
       registry.register(new Scheme("https", sf, 443)); 

       ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); 

       return new DefaultHttpClient(ccm, params); 
   } catch (Exception e) { 
       return new DefaultHttpClient(); 
   } 
}
 
開發者ID:gyqGitHub,項目名稱:WeiXinPayDemo,代碼行數:24,代碼來源:Util.java

示例2: testEdit

import org.apache.http.impl.client.DefaultHttpClient; //導入依賴的package包/類
@Test
public void testEdit() throws URISyntaxException, ClientProtocolException, IOException {
    String url = "http://127.0.0.1:8080/sjk-market-admin/admin/catalogconvertor/edit.json";
    URIBuilder urlb = new URIBuilder(url);

    // 參數
    urlb.setParameter("id", "1");
    urlb.setParameter("marketName", "eoemarket");
    urlb.setParameter("catalog", "1");
    urlb.setParameter("subCatalog", "15");
    urlb.setParameter("subCatalogName", "係統工具1");
    urlb.setParameter("targetCatalog", "1");
    urlb.setParameter("targetSubCatalog", "14");

    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(urlb.build());
    HttpResponse response = httpClient.execute(httpPost);
    logger.debug("URL:{}\n{}\n{}", url, response.getStatusLine(), response.getEntity());
}
 
開發者ID:zhaoxi1988,項目名稱:sjk,代碼行數:20,代碼來源:CatalogConvertorControllerTest.java

示例3: GetDate

import org.apache.http.impl.client.DefaultHttpClient; //導入依賴的package包/類
private String GetDate(String url) {
    String resultString = "";
    try {
        return EntityUtils.toString(new DefaultHttpClient().execute(new HttpGet(wwwhost +
                url)).getEntity());
    } catch (Exception e) {
        this._callback.onFailed(e.getMessage());
        return resultString;
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:11,代碼來源:LEYUApplication.java

示例4: get

import org.apache.http.impl.client.DefaultHttpClient; //導入依賴的package包/類
public static HttpClient get() {
    HttpParams httpParams = new BasicHttpParams();
    ConnManagerParams.setTimeout(httpParams, 3000);
    ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(30));
    ConnManagerParams.setMaxTotalConnections(httpParams, 30);
    HttpClientParams.setRedirecting(httpParams, true);
    HttpProtocolParams.setUseExpectContinue(httpParams, true);
    HttpConnectionParams.setStaleCheckingEnabled(httpParams, false);
    HttpConnectionParams.setSoTimeout(httpParams, 2000);
    HttpConnectionParams.setConnectionTimeout(httpParams, 2000);
    HttpConnectionParams.setTcpNoDelay(httpParams, true);
    HttpConnectionParams.setSocketBufferSize(httpParams, 8192);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme(IDataSource.SCHEME_HTTP_TAG, PlainSocketFactory.getSocketFactory(), 80));
    try {
        KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        trustStore.load(null, null);
        SSLSocketFactory sf = new MySSLSocketFactory(trustStore);
        sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        schemeRegistry.register(new Scheme(IDataSource.SCHEME_HTTPS_TAG, sf, 443));
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return new DefaultHttpClient(new ThreadSafeClientConnManager(httpParams, schemeRegistry), httpParams);
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:26,代碼來源:PoolingClientConnectionManager.java

示例5: getNewHttpClient

import org.apache.http.impl.client.DefaultHttpClient; //導入依賴的package包/類
private static HttpClient getNewHttpClient() { 
   try { 
       KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
       trustStore.load(null, null); 

       SSLSocketFactory sf = new SSLSocketFactoryEx(trustStore);
       sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

       HttpParams params = new BasicHttpParams();
       HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); 
       HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); 

       SchemeRegistry registry = new SchemeRegistry(); 
       registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); 
       registry.register(new Scheme("https", sf, 443)); 

       ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); 

       return new DefaultHttpClient(ccm, params); 
   } catch (Exception e) {
       return new DefaultHttpClient(); 
   } 
}
 
開發者ID:cheng2016,項目名稱:developNote,代碼行數:24,代碼來源:HttpUtil.java

示例6: initSubtitleResource

import org.apache.http.impl.client.DefaultHttpClient; //導入依賴的package包/類
public void initSubtitleResource(final String url) {
	new Thread(new Runnable() {

		@Override
		public void run() {
			try {
				HttpClient client = new DefaultHttpClient();
				client.getParams().setParameter(
						CoreConnectionPNames.CONNECTION_TIMEOUT, 5000);
				HttpGet httpGet = new HttpGet(url);
				HttpResponse response = client.execute(httpGet);
				HttpEntity entity = response.getEntity();
				String results = EntityUtils.toString(entity, "utf-8");
				parseSubtitleStr(results);
			} catch (Exception e) {
				Log.e("CCVideoViewDemo", "" + e.getMessage());
			}
		}
	}).start();
}
 
開發者ID:lbbniu,項目名稱:CCDownload,代碼行數:21,代碼來源:Subtitle.java

示例7: MyAnimeListQuery

import org.apache.http.impl.client.DefaultHttpClient; //導入依賴的package包/類
public MyAnimeListQuery(Charrizard charrizard) {
    status = MyAnimeListStatus.UNKNOWN_ERROR;
    errorDescription = "Unknown error.";
    try {
        HttpClient httpClient = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet("https://myanimelist.net/api/account/verify_credentials.xml");
        httpGet.addHeader(BasicScheme.authenticate(
                new UsernamePasswordCredentials(charrizard.getSettings().getMyAnimeList().getUsername(), charrizard.getSettings().getMyAnimeList().getUsername()),
                "UTF-8", false));

        HttpResponse httpResponse = httpClient.execute(httpGet);
        HttpEntity responseEntity = httpResponse.getEntity();
        if (httpResponse.getStatusLine().getStatusCode() >= 400) {
            status = MyAnimeListStatus.AUTH_ERROR;
            errorDescription = "Authorization Error: " + httpResponse.getStatusLine().getReasonPhrase();
            return;
        }
    } catch (IOException e) {
        status = MyAnimeListStatus.REQUEST_ERROR;
        errorDescription = "Can't connect to MyAnimeList: " + e.getMessage();
        e.printStackTrace();
    }
}
 
開發者ID:kacperduras,項目名稱:Charrizard,代碼行數:24,代碼來源:MyAnimeListQuery.java

示例8: downloadConfig

import org.apache.http.impl.client.DefaultHttpClient; //導入依賴的package包/類
private String[] downloadConfig(String url) throws Exception {
    try {
        HttpClient client = new DefaultHttpClient();
        HttpGet requestGet = new HttpGet(url);

        requestGet.addHeader("X-Android-MODEL", Build.MODEL);
        requestGet.addHeader("X-Android-SDK_INT", Integer.toString(Build.VERSION.SDK_INT));
        requestGet.addHeader("X-Android-RELEASE", Build.VERSION.RELEASE);
        requestGet.addHeader("X-App-Version", AppVersion);
        requestGet.addHeader("X-App-Install-ID", AppInstallID);
        requestGet.setHeader("User-Agent", System.getProperty("http.agent"));
        HttpResponse response = client.execute(requestGet);

        String configString = EntityUtils.toString(response.getEntity(), "UTF-8");
        String[] lines = configString.split("\\n");
        return lines;
    } catch (Exception e) {
        throw new Exception(String.format("Download config file from %s failed.", url));
    }
}
 
開發者ID:w22ee,項目名稱:onekey-proxy-android,代碼行數:21,代碼來源:ProxyConfig.java

示例9: sendRequest

import org.apache.http.impl.client.DefaultHttpClient; //導入依賴的package包/類
@Override
  protected RequestHandle sendRequest(DefaultHttpClient client,
                                      HttpContext httpContext, HttpUriRequest uriRequest,
                                      String contentType, ResponseHandlerInterface responseHandler,
                                      Context context) {
      if (contentType != null) {
          uriRequest.addHeader(AsyncHttpClient.HEADER_CONTENT_TYPE, contentType);
      }

      responseHandler.setUseSynchronousMode(true);

/*
       * will execute the request directly
*/
      newAsyncHttpRequest(client, httpContext, uriRequest, contentType, responseHandler, context).run();

      // Return a Request Handle that cannot be used to cancel the request
      // because it is already complete by the time this returns
      return new RequestHandle(null);
  }
 
開發者ID:benniaobuguai,項目名稱:android-project-gallery,代碼行數:21,代碼來源:SyncHttpClient.java

示例10: sendRequest

import org.apache.http.impl.client.DefaultHttpClient; //導入依賴的package包/類
/**
 * Puts a new request in queue as a new thread in pool to be executed
 *
 * @param client          HttpClient to be used for request, can differ in single requests
 * @param contentType     MIME body type, for POST and PUT requests, may be null
 * @param context         Context of Android application, to hold the reference of request
 * @param httpContext     HttpContext in which the request will be executed
 * @param responseHandler ResponseHandler or its subclass to put the response into
 * @param uriRequest      instance of HttpUriRequest, which means it must be of HttpDelete,
 *                        HttpPost, HttpGet, HttpPut, etc.
 * @return RequestHandle of future request process
 */
protected RequestHandle sendRequest(DefaultHttpClient client, HttpContext httpContext, HttpUriRequest uriRequest, String contentType, ResponseHandlerInterface responseHandler, Context context) {
    if (contentType != null) {
        uriRequest.addHeader("Content-Type", contentType);
    }

    responseHandler.setRequestHeaders(uriRequest.getAllHeaders());
    responseHandler.setRequestURI(uriRequest.getURI());

    Future<?> request = threadPool.submit(new AsyncHttpRequest(client, httpContext, uriRequest, responseHandler));

    if (context != null) {
        // Add request to request map
        List<WeakReference<Future<?>>> requestList = requestMap.get(context);
        if (requestList == null) {
            requestList = new LinkedList<WeakReference<Future<?>>>();
            requestMap.put(context, requestList);
        }

        requestList.add(new WeakReference<Future<?>>(request));

        // TODO: Remove dead weakrefs from requestLists?
    }

    return new RequestHandle(request);
}
 
開發者ID:zqHero,項目名稱:rongyunDemo,代碼行數:38,代碼來源:AsyncHttpClient.java

示例11: doInBackground

import org.apache.http.impl.client.DefaultHttpClient; //導入依賴的package包/類
@Override
protected Aluno doInBackground(String... rm) {

    //Instancia um cliente http, que fará a requisição do json
    DefaultHttpClient lHttpClient = new DefaultHttpClient();
    //Define um HttpGet, que contém a url
    HttpGet lHttpGet = new HttpGet(url.replace("$rm",rm[0]));
    try {
        //Executa e obtem a resposta da página da API
        HttpResponse lHttpResponse = lHttpClient.execute(lHttpGet);
        //Lê o resultado
        BufferedReader reader = new BufferedReader(new InputStreamReader(lHttpResponse.getEntity().getContent(), "UTF-8"));

        return analisar(reader.readLine());
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
開發者ID:alessandrojean,項目名稱:order-by-android,代碼行數:20,代碼來源:VerificaAluno.java

示例12: doInBackground

import org.apache.http.impl.client.DefaultHttpClient; //導入依賴的package包/類
@Override
protected List<String> doInBackground(String... url) {
    List<String> jsons = new ArrayList<String>();
    //Laço de repetição que percorre os quatro bimestres
    for(int i=0;i<4;i++) {
        //Instancia um cliente http, que fará a requisição do json
        DefaultHttpClient lHttpClient = new DefaultHttpClient();
        //Define um HttpGet, que contém a url
        HttpGet lHttpGet = new HttpGet(url[0].replace("$rm", mAluno).replace("$bim",String.valueOf(i+1)));
        try {
            //Executa e obtem a resposta da página da API
            HttpResponse lHttpResponse = lHttpClient.execute(lHttpGet);
            //Lê o resultado
            BufferedReader reader = new BufferedReader(new InputStreamReader(lHttpResponse.getEntity().getContent(), "UTF-8"));

            jsons.add(reader.readLine());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    return jsons;
}
 
開發者ID:alessandrojean,項目名稱:order-by-android,代碼行數:24,代碼來源:DownloadNotas.java

示例13: doInBackground

import org.apache.http.impl.client.DefaultHttpClient; //導入依賴的package包/類
@Override
protected List<String> doInBackground(String... url) {
    List<String> jsons = new ArrayList<String>();
    //Instancia um cliente http, que fará a requisição do json
    DefaultHttpClient lHttpClient = new DefaultHttpClient();
    //Define um HttpGet, que contém a url
    HttpGet lHttpGet = new HttpGet(url[0].replace("$turma", String.valueOf(mTurma)));
    try {
        //Executa e obtem a resposta da página da API
        HttpResponse lHttpResponse = lHttpClient.execute(lHttpGet);
        //Lê o resultado
        BufferedReader reader = new BufferedReader(new InputStreamReader(lHttpResponse.getEntity().getContent(), "UTF-8"));

        jsons.add(reader.readLine());
    } catch (Exception e) {
        e.printStackTrace();
    }

    return jsons;
}
 
開發者ID:alessandrojean,項目名稱:order-by-android,代碼行數:21,代碼來源:DownloadHorario.java

示例14: doInBackground

import org.apache.http.impl.client.DefaultHttpClient; //導入依賴的package包/類
@Override
protected List<String> doInBackground(String... url) {
    List<String> jsons = new ArrayList<String>();
    //Laço de repetição que percorre os doze mezes
    for(int i=0;i<12;i++) {
        //Instancia um cliente http, que fará a requisição do json
        DefaultHttpClient lHttpClient = new DefaultHttpClient();
        //Define um HttpGet, que contém a url
        HttpGet lHttpGet = new HttpGet(url[0].replace("$rm", mAluno).replace("$mes",String.valueOf(i+1)));
        try {
            //Executa e obtem a resposta da página da API
            HttpResponse lHttpResponse = lHttpClient.execute(lHttpGet);
            //Lê o resultado
            BufferedReader reader = new BufferedReader(new InputStreamReader(lHttpResponse.getEntity().getContent(), "UTF-8"));

            jsons.add(reader.readLine());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    return jsons;
}
 
開發者ID:alessandrojean,項目名稱:order-by-android,代碼行數:24,代碼來源:DownloadFaltas.java

示例15: getInstance

import org.apache.http.impl.client.DefaultHttpClient; //導入依賴的package包/類
/**
 * Returns the one <code>WebServiceUtil</code> instance
 * @return the one <code>WebServiceUtil</code> instance
 */
public static WebServiceUtil getInstance() {
  // This needs to be here instead of in the constructor because
  // it uses classes that are in the AndroidSDK and thus would
  // cause Stub! errors when running the component descriptor.
  synchronized(httpClientSynchronizer) {
    if (httpClient == null) {
      SchemeRegistry schemeRegistry = new SchemeRegistry();
      schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
      schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
      BasicHttpParams params = new BasicHttpParams();
      HttpConnectionParams.setConnectionTimeout(params, 20 * 1000);
      HttpConnectionParams.setSoTimeout(params, 20 * 1000);
      ConnManagerParams.setMaxTotalConnections(params, 20);
      ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params,
          schemeRegistry);
      WebServiceUtil.httpClient = new DefaultHttpClient(manager, params);
    }
  }
  return INSTANCE;
}
 
開發者ID:mit-cml,項目名稱:appinventor-extensions,代碼行數:25,代碼來源:WebServiceUtil.java


注:本文中的org.apache.http.impl.client.DefaultHttpClient類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。