RESTful request using HTTPUrlConnection-Collection of common programming errors
I’m writing my first Android app, and trying to get the hang of making a REST call from within the app. Following a couple pages and other SO posts, I’ve got this:
URL serverUrl = new URL("http://localhost:13980/api/maps/"); //the value is hardcoded for testing purposes
public String getMapsJson()
{
Log.d("Minimap", ">> getting maps json from " + serverUrl.toString());
String output = "";
HttpURLConnection connection = null;
try
{
connection = (HttpURLConnection) serverUrl.openConnection();
connection.setRequestMethod("GET");
Log.d("Minimap", "connection opened!");
InputStream in = new BufferedInputStream(connection.getInputStream());
Log.d("Minimap", "input stream captured");
output = readStream(in);
Log.d("Minimap", "stream read");
}
catch (Exception e)
{
Log.d("Minimap", e.getMessage()); //************* This is line 53