0

I am making simple request from Spring Boot app to URL.

URL url = new URL("http://...:8001/api/meta");

HttpURLConnection urlConnect = (HttpURLConnection) url.openConnection();
int code = urlConnect.getResponseCode(); 
...

code = 500. Then an error occurs:

Server returned HTTP response code: 500.

Also urlConnect.getErrorStream = null

If I put the url to browser then I successfully get json.

What should be done to fix the issue?

7
  • 2
    500 means an error on the server, not your client. Commented Apr 11, 2017 at 9:08
  • response code usually means, problem is on server side, so you should chech server side code to check what actually happened. Commented Apr 11, 2017 at 9:08
  • I don't think it is a server problem as I successfully get json when I put the url into browser. Commented Apr 11, 2017 at 9:10
  • Maybe track what actually goes on the line using NMAP or something alike. I guess there will be a difference between the requests from browser and URL.openConnection. Commented Apr 11, 2017 at 9:16
  • 2
    You may need to add "Accept: application/json" in your request. Commented Apr 11, 2017 at 9:16

1 Answer 1

0

I have added:

urlConnect.setRequestProperty("Accept", "application/json");

then I can successfully get the response.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.