我想在我的云中对多台服务器进行BIT(内置测试)。 我需要在超时时间长的情况下请求失败。
我应该如何使用Java实现这个功能?
尝试类似下面的代码似乎不起作用。
public class TestNodeAliveness {
public static NodeStatus nodeBIT(String elasticIP) throws ClientProtocolException, IOException {
HttpClient client = new DefaultHttpClient();
client.getParams().setIntParameter("http.connection.timeout", 1);
HttpUriRequest request = new HttpGet("http://192.168.20.43");
HttpResponse response = client.execute(request);
System.out.println(response.toString());
return null;
}
public static void main(String[] args) throws ClientProtocolException, IOException {
nodeBIT("");
}
}
-- 编辑:澄清正在使用的库 --
我正在使用来自Apache的httpclient库,这是相关的pom.xml部分:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.0.1</version>
<type>jar</type>
</dependency>