Java HTTP getResponseCode returns 200 for non-existent URL

后端 未结 5 364
长情又很酷
长情又很酷 2021-01-25 03:04

I was expecting this code to return a 404, however it produces the output :

\"Response code is 200\"

Would it be possible to learn how to differentiate between e

5条回答
  •  时光说笑
    2021-01-25 03:45

    You could:

    1. Resolve the IP from the host of the page
    2. Try to connect to port 80 on the resolved IP using plain sockets

    This is a bit low level however and will add complexity since you will need to make a simple GET request through the socket. Then validate the response so you're sure that its actually a HTTP server running on port 80.

    NMap might be able to help you here.

提交回复
热议问题