C
C
C_a_K_y_P_a2019-01-31 12:07:03
Java
C_a_K_y_P_a, 2019-01-31 12:07:03

Why can't I connect to the server?

Can't connect to php server.

The code
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;
    }
Here is the log

https://pastebin.com/D8QkE4Zh

I can't figure out why it won't connect.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question