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