How can I programmatically test an HTTP connection?

前端 未结 4 1779
时光说笑
时光说笑 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:52

    System.out.println(new InetSocketAddress("http://stackoverflow.com/about", 80).isUnresolved());
    

    delivers false if page is reachable, which is a precondition.

    In order to cover initial question completely, you need to implement a http get or post.

提交回复
热议问题