How can I programmatically test an HTTP connection?

前端 未结 4 1774
时光说笑
时光说笑 2020-12-09 04:04

Using Java, how can I test that a URL is contactable, and returns a valid response?

http://stackoverflow.com/about
4条回答
  •  天命终不由人
    2020-12-09 04:57

    Since java 5 if i recall, the InetAdress class contains a method called isReachable(); so you can use it to make a ping implementation in java. You can also specify a timeout for this method. This is just another alternative to the unit test method posted above, which is probably more efficient.

提交回复
热议问题