我想在我的云中为多个服务器制作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("");
}
}
Run Code Online (Sandbox Code Playgroud)
- 编辑:澄清正在使用的库 -
我正在使用apache的httpclient,这是相关的pom.xml部分
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.0.1</version>
<type>jar</type>
</dependency>
Run Code Online (Sandbox Code Playgroud)