本文整理汇总了Java中android.net.http.AndroidHttpClient.close方法的典型用法代码示例。如果您正苦于以下问题:Java AndroidHttpClient.close方法的具体用法?Java AndroidHttpClient.close怎么用?Java AndroidHttpClient.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.net.http.AndroidHttpClient
的用法示例。
在下文中一共展示了AndroidHttpClient.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: downloadUriAsString
import android.net.http.AndroidHttpClient; //导入方法依赖的package包/类
private static String downloadUriAsString(final HttpUriRequest req)
throws IOException {
AndroidHttpClient client = AndroidHttpClient.newInstance(userAgentString());
try {
HttpResponse res = client.execute(req);
return readToEnd(res.getEntity().getContent());
} finally {
client.close();
}
}
示例2: doInBackground
import android.net.http.AndroidHttpClient; //导入方法依赖的package包/类
@Override
protected VastVideoConfiguration doInBackground(@Nullable String... strings) {
AndroidHttpClient httpClient = null;
try {
httpClient = HttpClient.getHttpClient();
if (strings != null && strings.length > 0) {
String vastXml = strings[0];
if (vastXml == null) {
return null;
}
return evaluateVastXmlManager(vastXml, httpClient, new ArrayList<VastTracker>());
}
} catch (Exception e) {
MoPubLog.d("Failed to parse VAST XML", e);
} finally {
if (httpClient != null) {
httpClient.close();
}
}
return null;
}
示例3: doInBackground
import android.net.http.AndroidHttpClient; //导入方法依赖的package包/类
@Override
protected DownloadResponse doInBackground(final HttpUriRequest... httpUriRequests) {
if (httpUriRequests == null || httpUriRequests.length == 0 || httpUriRequests[0] == null) {
MoPubLog.d("Download task tried to execute null or empty url");
return null;
}
final HttpUriRequest httpUriRequest = httpUriRequests[0];
mUrl = httpUriRequest.getURI().toString();
AndroidHttpClient httpClient = null;
try {
httpClient = HttpClient.getHttpClient();
final HttpResponse httpResponse = httpClient.execute(httpUriRequest);
return new DownloadResponse(httpResponse);
} catch (Exception e) {
MoPubLog.d("Download task threw an internal exception", e);
return null;
} finally {
if (httpClient != null) {
httpClient.close();
}
}
}
示例4: doInBackground
import android.net.http.AndroidHttpClient; //导入方法依赖的package包/类
@Override
protected HttpResponse doInBackground(String... params) {
String link = params[0];
String payload = params[1];
AndroidHttpClient client = AndroidHttpClient.newInstance("Android");
HttpPost request = new HttpPost(link);
HttpResponse response = null;
request.setHeader( "Content-Type", "application/json" );
try {
StringEntity se = new StringEntity(payload);
se.setContentEncoding("UTF-8");
se.setContentType("application/json");
request.setEntity(se);
response = client.execute(request);
} catch (IOException e) {
log(e.getMessage());
e.printStackTrace();
} finally {
client.close();
}
return response;
}
示例5: HttpGetAnswer
import android.net.http.AndroidHttpClient; //导入方法依赖的package包/类
public static String HttpGetAnswer(String url) throws ClientProtocolException, IOException, JSONException, HttpException{
AndroidHttpClient client = AndroidHttpClient.newInstance(null);
client.getParams().setParameter(HttpConnectionParams.CONNECTION_TIMEOUT, 7500);
client.getParams().setParameter(HttpConnectionParams.SO_TIMEOUT, 7500);
HttpGet httpGet = new HttpGet(url);
HttpResponse response = client.execute(httpGet);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {
String resp = EntityUtils.toString(response.getEntity());
client.close();
return resp;
} else {
try {
client.close();
}catch (Exception ex){}
throw new HttpException("STATUSCODE!=200");
}
}
示例6: HttpPostAnswer
import android.net.http.AndroidHttpClient; //导入方法依赖的package包/类
public static String HttpPostAnswer(String url, JSONObject jobj) throws ClientProtocolException, IOException, JSONException, HttpException{
AndroidHttpClient client = AndroidHttpClient.newInstance(null);
client.getParams().setParameter(HttpConnectionParams.CONNECTION_TIMEOUT, 7500);
client.getParams().setParameter(HttpConnectionParams.SO_TIMEOUT, 7500);
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new StringEntity(jobj.toString()));
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");
HttpResponse response = client.execute(httpPost);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {
String resp = EntityUtils.toString(response.getEntity());
client.close();
return resp;
} else {
try {
client.close();
}catch (Exception ex){}
throw new HttpException("STATUSCODE!=200");
}
}
示例7: HttpPostAnswerJsonObject
import android.net.http.AndroidHttpClient; //导入方法依赖的package包/类
public static JSONObject HttpPostAnswerJsonObject(String url, JSONObject obj) throws ClientProtocolException, IOException, JSONException, HttpException{
AndroidHttpClient client = AndroidHttpClient.newInstance(null);
client.getParams().setParameter(HttpConnectionParams.CONNECTION_TIMEOUT, 60000);
client.getParams().setParameter(HttpConnectionParams.SO_TIMEOUT, 60000);
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new StringEntity(obj.toString()));
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");
HttpResponse response = client.execute(httpPost);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {
String raw = EntityUtils.toString(response.getEntity());
JSONObject jobj = new JSONObject(raw);
client.close();
return jobj;
} else {
try {
client.close();
}catch (Exception ex){}
throw new HttpException("STATUSCODE!=200");
}
}
示例8: HttpPostAnswerJsonArray
import android.net.http.AndroidHttpClient; //导入方法依赖的package包/类
public static JSONArray HttpPostAnswerJsonArray(String url, JSONObject obj) throws ClientProtocolException, IOException, JSONException, HttpException{
AndroidHttpClient client = AndroidHttpClient.newInstance(null);
client.getParams().setParameter(HttpConnectionParams.CONNECTION_TIMEOUT, 10000);
client.getParams().setParameter(HttpConnectionParams.SO_TIMEOUT, 10000);
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new StringEntity(obj.toString()));
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");
HttpResponse response = client.execute(httpPost);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {
String raw = EntityUtils.toString(response.getEntity());
JSONArray jarr = new JSONArray(raw);
client.close();
return jarr;
} else {
try {
client.close();
}catch (Exception ex){}
throw new HttpException("STATUSCODE!=200");
}
}
示例9: checkUrl
import android.net.http.AndroidHttpClient; //导入方法依赖的package包/类
/**
* Check if a URL is valid and points to a resource on the remote web
* server. Used to check if certain image sizes are available.
*
* @param url
* @return
*/
public static boolean checkUrl(String url) {
Log.d(LOG_TAG, "checkUrl: " + url);
final AndroidHttpClient client = AndroidHttpClient.newInstance("Android");
final HttpGet request = new HttpGet(url);
try {
HttpResponse response = client.execute(request);
final int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == HttpStatus.SC_OK) {
return true;
}
} catch (Exception e) {
request.abort();
} finally {
if (client != null) {
client.close();
}
}
return false;
}
示例10: doRequest
import android.net.http.AndroidHttpClient; //导入方法依赖的package包/类
private static BackendConnectionResult doRequest(HttpUriRequest request) {
RequestAnalytics analytics = new RequestAnalytics(request);
AndroidHttpClient httpClient = AndroidHttpClient.newInstance(userAgent);
BackendConnectionResult result;
try {
HttpResponse response = httpClient.execute(request);
InputStream inputStream = response.getEntity().getContent();
StatusLine statusLine = response.getStatusLine();
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, Charsets.UTF_8);
String contentString = CharStreams.toString(inputStreamReader);
inputStreamReader.close();
httpClient.close();
result = new BackendConnectionResult(statusLine, contentString);
} catch (IOException e) {
result = new BackendConnectionResult(e);
}
analytics.done(result);
return result;
}
示例11: doInBackground
import android.net.http.AndroidHttpClient; //导入方法依赖的package包/类
@Override
protected Boolean doInBackground(final String... params) {
if (params == null || params[0] == null) {
return false;
}
final String videoUrl = params[0];
AndroidHttpClient httpClient = null;
try {
httpClient = HttpClient.getHttpClient();
final HttpGet httpget = HttpClient.initializeHttpGet(videoUrl);
final HttpResponse response = httpClient.execute(httpget);
if (response == null || response.getEntity() == null) {
throw new IOException("Obtained null response from video url: " + videoUrl);
}
if (response.getEntity().getContentLength() > MAX_VIDEO_SIZE) {
throw new IOException("Video exceeded max download size");
}
final InputStream inputStream = new BufferedInputStream(response.getEntity().getContent());
final boolean diskPutResult = CacheService.putToDiskCache(videoUrl, inputStream);
inputStream.close();
return diskPutResult;
} catch (Exception e) {
MoPubLog.d("Failed to download video: " + e.getMessage());
return false;
} finally {
if (httpClient != null) {
httpClient.close();
}
}
}
示例12: doInBackground
import android.net.http.AndroidHttpClient; //导入方法依赖的package包/类
@Override
protected RestResult doInBackground(String... args) {
try {
request = createRequest();
if (isCancelled())
throw new InterruptedException();
OAuthConsumer consumer = Session.getInstance().getOAuthConsumer();
if (consumer != null) {
AccessToken accessToken = Session.getInstance().getAccessToken();
if (accessToken != null) {
consumer.setTokenWithSecret(accessToken.getKey(), accessToken.getSecret());
}
consumer.sign(request);
}
request.setHeader("Accept-Language", Locale.getDefault().getLanguage());
request.setHeader("API-Client", String.format("uservoice-android-%s", UserVoice.getVersion()));
AndroidHttpClient client = AndroidHttpClient.newInstance(String.format("uservoice-android-%s", UserVoice.getVersion()), Session.getInstance().getContext());
if (isCancelled())
throw new InterruptedException();
// TODO it would be nice to find a way to abort the request on cancellation
HttpResponse response = client.execute(request);
if (isCancelled())
throw new InterruptedException();
HttpEntity responseEntity = response.getEntity();
StatusLine responseStatus = response.getStatusLine();
int statusCode = responseStatus != null ? responseStatus.getStatusCode() : 0;
String body = responseEntity != null ? EntityUtils.toString(responseEntity) : null;
client.close();
if (isCancelled())
throw new InterruptedException();
return new RestResult(statusCode, new JSONObject(body));
} catch (Exception e) {
return new RestResult(e);
}
}
示例13: execute
import android.net.http.AndroidHttpClient; //导入方法依赖的package包/类
@Override
public ServiceFilterResponse execute() throws Exception {
// Execute request
AndroidHttpClient client = AndroidHttpClient.newInstance(getUserAgent());
try {
final HttpResponse response = client.execute(mRequest);
ServiceFilterResponse serviceFilterResponse = new ServiceFilterResponseImpl(response);
return serviceFilterResponse;
} finally {
client.close();
}
}
示例14: loadCsvHelper
import android.net.http.AndroidHttpClient; //导入方法依赖的package包/类
protected static void loadCsvHelper(Context context, String csvUrl,
String tableName, CsvMapping mapping) {
AndroidHttpClient httpClient = AndroidHttpClient.newInstance("AquaBase"); //$NON-NLS-1$
try {
// Grab the csv file and parse it
HttpResponse response = httpClient.execute(new HttpGet(csvUrl));
parseCsv(context, response.getEntity().getContent(), tableName, mapping);
} catch (Exception e) {
Log.e("Trace", "Failed to load CSV file", e); //$NON-NLS-1$ //$NON-NLS-2$
}
httpClient.close();
}
示例15: tryLogin
import android.net.http.AndroidHttpClient; //导入方法依赖的package包/类
public static boolean tryLogin(String username, String password) throws CommunicationInterface.ParsingException, IOException, CommunicationInterface.CommunicationException {
AndroidHttpClient httpClient = AndroidHttpClient.newInstance(null);
CookieStore cookies = new BasicCookieStore();
HttpContext localContext = new BasicHttpContext();
localContext.setAttribute(ClientContext.COOKIE_STORE, cookies);
boolean result = tryLogin(httpClient, localContext, username, password);
// cleanup
httpClient.close();
return result;
}