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?

Kirill Ch
  • 5,496
  • 4
  • 44
  • 65

1 Answers1

0

I have added:

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

then I can successfully get the response.

Kirill Ch
  • 5,496
  • 4
  • 44
  • 65