Java HTTP getResponseCode returns 200 for non-existent URL

后端 未结 5 428
长情又很酷
长情又很酷 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:48

    Ideally you should be getting this error:

    java.net.UnknownHostException: www.thisurldoesnotexist
    

    But it looks like your URL is resolved by you DNS provider.

    For instance on my company's network running your code with URI "http://profile/" displays the employee profile.

    Please also check etc.home file if you are on windows to check if any settings have been changed.

提交回复
热议问题