1

I have a problem reading the content of an URL in my AsyncTask:

@Override
protected String doInBackground(String... args) {
    HttpURLConnection urlConnection = null;
    StringBuilder result = new StringBuilder();

    try {
        URL url = new URL(args[0]);

        urlConnection = (HttpURLConnection) url.openConnection();
        urlConnection.setRequestMethod("GET");

        InputStream in = new BufferedInputStream(urlConnection.getInputStream());
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));

        String line;
        while ((line = reader.readLine()) != null) {
            result.append(line);
        }
        in.close();
    }catch( Exception e) {
        e.printStackTrace();
    }
    finally {
        urlConnection.disconnect();
    }

    return result.toString();

}

In the main activity:

    String cont="";
    asyncT t = new asyncT();

    try {
        cont = t.execute("http://wardenlotro.epizy.com/").get();
    }
    catch (Exception e){
        e.printStackTrace();
    }

I need the web conent, but i get this:

<html><body><script type="text/javascript" src="/aes.js" ></script><script>function toNumbers(d){var e=[];d.replace(/(..)/g,function(d){e.push(parseInt(d,16))});return e}function toHex(){for(var d=[],d=1==arguments.length&&arguments[0].constructor==Array?arguments[0]:arguments,e="",f=0;f<d.length;f++)e+=(16>d[f]?"0":"")+d[f].toString(16);return e.toLowerCase()}var a=toNumbers("f655ba9d09a112d4968c63579db590b4"),b=toNumbers("98344c2eee86c3994890592585b49f80"),c=toNumbers("202588dd6fbc15306fac1235140f8b84");document.cookie="__test="+toHex(slowAES.decrypt(c,2,a,b))+"; expires=Thu, 31-Dec-37 23:55:55 GMT; path=/"; location.href="http://wardenlotro.epizy.com/?i=1";</script><noscript>This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support</noscript></body></html>

The index.php file in the server now only have echo "Hi World";

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • calling get makes your synchronous. Also you need to parse html tags to get the contents. look for jsoup – Raghunandan Apr 13 '18 at 10:57
  • Remove the .get() from the async task and attach the logs. – Ashish Kumar Apr 13 '18 at 11:05
  • What content do you get when you open http://wardenlotro.epizy.com/ on the device in a web browser? It looks like your AsyncTask is hitting some captive portal page (like wifi login) instead of the URL you're aiming for. – Philipp Reichart Apr 13 '18 at 11:08
  • The device gets "Hi World" text content in a web browser. – Oscar Martinez Gomez Apr 13 '18 at 11:24
  • try it https://stackoverflow.com/questions/2075836/read-contents-of-a-url-in-android?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa –  Apr 13 '18 at 12:06
  • Solved. I created the same web page in another free trial server and read the content without problems. It will be a problem of the server where the bd is hosted and the web that I do not know what it will do or ask when making the connection. – Oscar Martinez Gomez Apr 16 '18 at 04:14

0 Answers0