0

I want to fire a blocking call to my php file which queries my db. I want it to be blocking and not async as i don't want the user shown anything until this call is successful or not.

I run the below code, it stops at response = httpclient.execute(httpget); for a minute or two before going into catch for error. I cant see an error in the e item.

Anybody know whats going on here - my php file works with async task.

public static String blockingHttpCallToUrl(String url)
{
    String result="nothingReturned";
    HttpClient httpclient = new DefaultHttpClient();

    // Prepare a request object
    HttpGet httpget = new HttpGet(url);

    // Execute the request
    HttpResponse response;
    try {
        response = httpclient.execute(httpget);
        // Examine the response status
        Log.i("Praeda", response.getStatusLine().toString());

        // Get hold of the response entity
        HttpEntity entity = response.getEntity();
        // If the response does not enclose an entity, there is no need
        // to worry about connection release

        if (entity != null) {
            // A Simple JSON Response Read
            InputStream instream = entity.getContent();
            result= convertStreamToString(instream);
            // now you have the string representation of the HTML request
            instream.close();
        }


    } catch (Exception e) {}

    return result;
}
Fearghal
  • 10,569
  • 17
  • 55
  • 97
  • e.getMessage() tells nothing? Put e.printStackTrace(); in it too and post the logcat. – greenapps Mar 30 '15 at 13:23
  • Yea i cant see where this e.printToStackTrace is printed to. I run my app in debug mode, look at 'android' tab and 'devices|logcat' but nothing recognisable fromt he 100's of lines that flash past after i hit the breakpoint at issue – Fearghal Mar 30 '15 at 15:46
  • e.getMessage() is null. – Fearghal Mar 30 '15 at 15:48

0 Answers0