0
votes

(Sorry for any english mistake its not my native language)

I'm trying to parse html using Volley and Jsoup. while debugging / running the app, the StringRequest dosent invoke onResponse() or onErrorResponse(), basically there no response or Error from the Response.Listener (i guess). so i cant "begin" parsing the html because the onResponse() is never invoked. Ive searched for answer and nothing seems to get it fixed.

Could it be that the RequestQueue cache kicks in and its not trying to get the response? (just brain storming tried so many things).

--Im just trying to retrive data from html, so i could show the updated data from the url in my app, is Volly the way or should i use simpler mathods?

here is my volley StringRequest and RequestQueue:

String url = "http://www.fringeb7.co.il/";
final RequestQueue requestQueue = Volley.newRequestQueue(MainActivity.this);
// Request a string response from the provided URL.
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
        new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    response_utf8 = URLDecoder.decode(URLEncoder.encode(response, "iso8859-1"),"UTF-8");
                    doc = Jsoup.parse(response_utf8);
                    Log.d("logr=",response);
                }
            },
        new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    error.printStackTrace();
                    Log.d("log2=", error.toString());
                    requestQueue.stop();
                }
    });
    // Add the request to the RequestQueue.
    requestQueue.add(stringRequest);
3

3 Answers

0
votes

took me long enough, but there was no problem. the code works, while debugging there were no response, but when i run the app the request complete and i got the wanted response.

so if anyone have a similier problem, from some reason while debugging I dident get response but while running the app its working fine. (simpley dident know that)

try this first before wasting time in debugging like i did.

0
votes

If you use Jsoup, you can get it and parse in very simple way:

Document doc = Jsoup.connect("http://www.fringeb7.co.il/").get();

If you still want to use Volley, below code works perfectly in my device:

    String url = "http://www.fringeb7.co.il/";
    RequestQueue requestQueue = Volley.newRequestQueue(MainActivity.this);
    // Request a string response from the provided URL.
    StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        String response_utf8 = URLDecoder.decode(URLEncoder.encode(response, "iso8859-1"), "UTF-8");
                        Document doc = Jsoup.parse(response_utf8);
                        Log.d("logr=", "title = " + doc.title());
                    } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                    }
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    error.printStackTrace();
                    Log.d("log2=", error.toString());
                    //requestQueue.stop();
                }
            });
    // Add the request to the RequestQueue.
    requestQueue.add(stringRequest);
    requestQueue.start();

Output of the above code:

D/logr=: title = תיאטרון הפרינג' באר שבע
0
votes

try 'https' instead of 'http' in your url