[java] Server returned HTTP response code: 400

I am trying to get an InputStream from a URL. The URL can be a opened from Firefox. It returns a json and I have installed an addon for viewing json in Firefox so I can view it there.

So I tried to get it from Java by:

URL url = new URL(urlString);
URLConnection urlConnection = url.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));

But it is throwing an IOException in urlConnection.getInputStream().

I also tried:

HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
InputStream inputStream = url.openStream();

But no luck.

Any information is appreciable. Thanks in advance.

This question is related to java url ioexception http-status-code-400

The answer is


Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to url

What is the difference between URL parameters and query strings? Allow Access-Control-Allow-Origin header using HTML5 fetch API File URL "Not allowed to load local resource" in the Internet Browser Slack URL to open a channel from browser Getting absolute URLs using ASP.NET Core How do I load an HTTP URL with App Transport Security enabled in iOS 9? Adding form action in html in laravel React-router urls don't work when refreshing or writing manually URL for public Amazon S3 bucket How can I append a query parameter to an existing URL?

Examples related to ioexception

Run a command shell in jenkins IOException: The process cannot access the file 'file path' because it is being used by another process java IO Exception: Stream Closed What throws an IOException in Java? Server returned HTTP response code: 400 Error message "unreported exception java.io.IOException; must be caught or declared to be thrown" When is "java.io.IOException:Connection reset by peer" thrown? Cannot make file java.io.IOException: No such file or directory SQLRecoverableException: I/O Exception: Connection reset Unable to read data from the transport connection : An existing connection was forcibly closed by the remote host

Examples related to http-status-code-400

Returning http 200 OK with error within response body 400 BAD request HTTP error code meaning? Getting 400 bad request error in Jquery Ajax POST How to send Request payload to REST API in java? Server returned HTTP response code: 400 HTTP 400 (bad request) for logical error, not malformed request syntax