I have apache spring REST running locally on my computer. I would like to use this api for Android development.
Here is my request for receipt:
public static String sendGet(final String url) {
StringBuilder result = new StringBuilder();
HttpURLConnection urlConnection = null;
try {
String apiUrl = getAbsoluteUrl(url);
URL requestUrl = new URL(apiUrl);
urlConnection = (HttpURLConnection) requestUrl.openConnection();
urlConnection.connect();
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line;
while ((line = reader.readLine()) != null) {
result.append(line);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
urlConnection.disconnect();
}
return result.toString();
}
I can access my api through the browser of my device. However, when I use the same URL inside the built-in apk to execute the request, the connection is not made.
My manifest includes:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Side notes:
I connect my device to a laptop using the rest of the api via usb. I am using the WLAN IP address found by calling ipconfig.
Any advice in the right direction would be greatly appreciated - thanks!
Chrome ( Android) REST api, ( GET ):
