Question

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

Posted May 23, 2019 1.4k views
ApacheJavaUbuntu 18.04

Hi,

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.

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.

×
1 answer

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.

Submit an Answer