I can send a request to my RestApi with curl but I cannot reach service from browser


I have a rest-api written in Java.

When I run my project by java -jar xx.jar command and send a curl request as "curl -X GET “http://mysitename:8084/metadata/city/34” -H “accept: application/json;charset=UTF-8” it works.

But when I enter same address as “http://mysitename:8084/metadata/city/34” to browser, it does not respond and gives this error: “mysitename’s server IP address could not be found”.

I also have swagger dependencies on my pom.xml and “http://mysitename:8084/swagger-ui.html” does not respond also.

So, any help would be very much appreciated.


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

What’s failing is DNS resolution. When you are doing curl from the commandline the first place that your nameserver will check for definitions is your /etc/hosts file. If there you have a definition for a domain or name to point to an IP then it will use that to make the request.

When you are going from your browser there is similar behavior depending on whether you are using Mac or Windows. So most likely there is a misconfiguration between your /etc/hosts setting between your server and your local machine which is why when you goto the browser you get the error.

Now if you have a full domain in there, instead of mysitename as a place holder, you would need to check DNS resolution of that domain from both environments to see what the issue is.