我正在尝试使用 CloseableHttpClient 通过Spring Boot将此Perl代码转换为Java代码,但是在Java中,获取事件非常慢。如何将保持活动状态设置为0?
Perl:
use strict;
use LWP::UserAgent;
use HTTP::Headers;
my $ua = LWP::UserAgent->new('keep_alive' => 0, timeout => 7200);
while (1)
{
my $request = HTTP::Request->new("GET",'https://events.voip.ovh.net', HTTP::Headers->new(), "\n\n");
my $response = $ua->request($request);
if ($response->is_success)
{
print $response->content."\n";
}
}
Java:
CloseableHttpClient configureCloseableHttpclient() {
RequestConfig config = RequestConfig.custom()
.setSocketTimeout(5 * 1000)
.setConnectTimeout(5 * 1000).build();
return HttpClients.custom().setConnectionManager(new PoolingHttpClientConnectionManager()).setDefaultRequestConfig(config)
.build();
}