class RequestTask extends AsyncTask<String, String, String> {
String result;
@Override
protected String doInBackground(String... uri) {
HttpURLConnection conn = null;
try{
URL url = new URL("http://vse-team.ru/connect.php");
conn = (HttpURLConnection)url.openConnection();
//conn.setRequestMethod("GET");
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 (.NET CLR 3.5.30729)");
conn.setUseCaches(false);
conn.setConnectTimeout(200);
conn.setReadTimeout(200);
conn.connect();
result = "ok!";
StringBuilder sb = new StringBuilder();
if(HttpURLConnection.HTTP_OK == conn.getResponseCode()) {
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while((line = in.readLine()) != null) {
sb.append(line);
sb.append("\n");
}
result = sb.toString();
result = "ok!";
}
} catch (Throwable c) {
c.printStackTrace();
}
finally {
if(conn != null) {
conn.disconnect();
}
}
return result;
}