I'd like to use http://www.imdbapi.com/ in Java, but I don't know I can access the http response. I tried the following:
public Map<String, String> get(String title)
{
URL url = new URL("http://www.imdbapi.com/?t=" + title);
URLConnection conn = url.openConnection();
conn.getContent();
}
I recomend use http-request built on apache http api.
When you go the website and type in the sample movie (i did True Grit ) you are actually able to see the response you would be getting. It looks something like this:
After knowing this info, you can easily parse your InputStream, which you obtain from your connection.
Good luck!
The below code should get you started. You need to add URL encoding if you are going to send special characters. In-order to parse JSON response you could probably use parser available in java at [link] http://www.JSON.org/
You can use
URLConnection#getInputStream()
:Or just the shorthand
URL#openStream()
directly:Once having it, just send it to a JSON parser of your choice, such as for example Gson:
(note that I fixed your query string to be properly URL encoded)
See also: