I am trying to access an IP address from my android app but I am not have any luck. Here is my async task that I am trying:
protected String doInBackground(Void...arg0) {
try{
URL url = new URL(myIP);
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
String read = readStream(con.getInputStream());
return read;
} catch(Exception e){
e.printStackTrace();
}
return null;
}
private String readStream(InputStream in){
BufferedReader reader = null;
StringBuilder sb = new StringBuilder("xxxx");
try{
reader = new BufferedReader(new InputStreamReader(in));
String line = "";
while((line = reader.readLine()) != null){
sb.append(line + "\n");
}
} catch(IOException e){
e.printStackTrace();
} finally{
if(reader != null){
try{
reader.close();
} catch(IOException e){
e.printStackTrace();
}
}
}
return sb.toString();
}
protected void onPostExecute(String result){
textView.setText(result);
}
When I use a normal url like www.stackoverflow.com it works fine, but when I try to use an IP there is just no response whatsoever. It's not throwing any exceptions and it is not updating the textView(I have tried returning different results based on which exception is thrown). So this brings me to my question, is an IP address a valid input for a URLconnection? Let me know if there is any other information I can provide.
It also may be helpful that my end goal is to send REST requests to this IP to access particular information.