I wrote a function for my self, that can request any URL. You can also define the method (POST, GET, etc. ) and the body of data, if you have something to send.
public static String requestURL(URL url, String method, String body){
String result = "";
HttpURLConnection httpCon = null;
try {
httpCon = (HttpURLConnection) url.openConnection();
assert httpCon != null;
httpCon.setDoOutput(true);
httpCon.setRequestMethod(method);
OutputStreamWriter out = null;
out = new OutputStreamWriter(httpCon.getOutputStream());
assert out != null;
out.write(body);
out.close();
httpCon.getInputStream();
InputStream is = null;
result = "";
is = new BufferedInputStream(httpCon.getInputStream());
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String inputLine = "";
while ((inputLine = br.readLine()) != null) {
result += inputLine;
}
return result;
}catch (Exception e){
return "{\"nothing\":\"nothing\"}";
}
}
I am using the HTTPURLConnection to accomplish this.
PS. Sorry for my bad code, but this was something, which works every time for me, even in my earliest states of programming experience for Android.