HttpContext localContext = new BasicHttpContext();
AuthSchemeBase authScheme = new BasicScheme();
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
CloseableHttpAsyncClient httpAsyncClient = HttpAsyncClients.custom().setDefaultCredentialsProvider(credentialsProvider).build();
httpAsyncClient.start();
Future<HttpResponse> future = httpAsyncClient.execute(request, localContext, null);
HttpResponse response = future.get();
if (response != null) {
StatusLine statusLine = response.getStatusLine();
if (statusLine != null) {
logger.warn(requestURL + " " + statusLine.toString());
if (statusLine.getStatusCode() == HttpStatus.SC_OK) {
byte[] bytes = EntityUtils.toByteArray(response.getEntity());
return new String(bytes, WeiboConstants.CHARSET_UTF8);
}
}
}
AuthSchemeBase authScheme = new BasicScheme();
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
CloseableHttpAsyncClient httpAsyncClient = HttpAsyncClients.custom().setDefaultCredentialsProvider(credentialsProvider).build();
httpAsyncClient.start();
Future<HttpResponse> future = httpAsyncClient.execute(request, localContext, null);
HttpResponse response = future.get();
if (response != null) {
StatusLine statusLine = response.getStatusLine();
if (statusLine != null) {
logger.warn(requestURL + " " + statusLine.toString());
if (statusLine.getStatusCode() == HttpStatus.SC_OK) {
byte[] bytes = EntityUtils.toByteArray(response.getEntity());
return new String(bytes, WeiboConstants.CHARSET_UTF8);
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货