parent
a84f073a0a
commit
1c66511bff
@ -781,25 +781,29 @@ public abstract class AbsSender {
|
||||
// Simplified methods
|
||||
|
||||
private void sendApiMethodAsync(BotApiMethod method, SentCallback callback) {
|
||||
exe.submit(() -> {
|
||||
try {
|
||||
CloseableHttpClient httpclient = HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()).build();
|
||||
String url = getBaseUrl() + method.getPath();
|
||||
HttpPost httppost = new HttpPost(url);
|
||||
httppost.addHeader("charset", StandardCharsets.UTF_8.name());
|
||||
httppost.setEntity(new StringEntity(method.toJson().toString(), ContentType.APPLICATION_JSON));
|
||||
CloseableHttpResponse response = httpclient.execute(httppost);
|
||||
HttpEntity ht = response.getEntity();
|
||||
BufferedHttpEntity buf = new BufferedHttpEntity(ht);
|
||||
String responseContent = EntityUtils.toString(buf, StandardCharsets.UTF_8);
|
||||
exe.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
CloseableHttpClient httpclient = HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()).build();
|
||||
String url = getBaseUrl() + method.getPath();
|
||||
HttpPost httppost = new HttpPost(url);
|
||||
httppost.addHeader("charset", StandardCharsets.UTF_8.name());
|
||||
httppost.setEntity(new StringEntity(method.toJson().toString(), ContentType.APPLICATION_JSON));
|
||||
CloseableHttpResponse response = httpclient.execute(httppost);
|
||||
HttpEntity ht = response.getEntity();
|
||||
BufferedHttpEntity buf = new BufferedHttpEntity(ht);
|
||||
String responseContent = EntityUtils.toString(buf, StandardCharsets.UTF_8);
|
||||
|
||||
JSONObject jsonObject = new JSONObject(responseContent);
|
||||
if (!jsonObject.getBoolean(Constants.RESPONSEFIELDOK)) {
|
||||
callback.onError(method, jsonObject);
|
||||
JSONObject jsonObject = new JSONObject(responseContent);
|
||||
if (!jsonObject.getBoolean(Constants.RESPONSEFIELDOK)) {
|
||||
callback.onError(method, jsonObject);
|
||||
}
|
||||
callback.onResult(method, jsonObject);
|
||||
} catch (IOException e) {
|
||||
callback.onException(method, e);
|
||||
}
|
||||
callback.onResult(method, jsonObject);
|
||||
} catch (IOException e) {
|
||||
callback.onException(method, e);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user