本文整理汇总了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();
}
}
示例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());
}
示例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;
}
}
示例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);
}
示例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();
}
}
示例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();
}
示例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();
}
}
示例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));
}
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}