Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
The following code I produced following a tutorial on web services, but nothing is happening although no error is given. Can anyone help me please? as I cannot continue. I need to connect to a web service and this is not working.

Using the debugger i found out that it is stopping in the first method on this particular line:
Java
HttpResponse response = client.execute(request);


This is my code:

Java
private String result = "";

 public void getResponse()
    {
        HttpClient client = new DefaultHttpClient();    
        String query ="working url";

        try
        {
            URL url = new URL(query);
            URI uri = new URI(url.getProtocol(), url.getHost(),url.getPath(), url.getQuery(),null);
            HttpGet request = new HttpGet(uri);
            HttpResponse response = client.execute(request);
            result=Userrequest(response); 

        }
        catch(Exception ex)
        {

        }




    }
    public String Userrequest(HttpResponse response)
    {
        try     
        {
            InputStream in = response.getEntity().getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(in));
            StringBuilder str = new StringBuilder();
            String line = null;
            while((line = reader.readLine()) != null)
                    {
                        str.append(line + "\n");
                    }
            in.close();
            result = str.toString();
            updateData(result);         
        }
        catch(Exception ex)
        {
            //responsetxt.setText(ex.getMessage());
        }
        return result;
    }
    public void updateData(String result)
    {
        try     
        {
            JSONObject json = new JSONObject(result);
            JSONArray ja;
            json = json.getJSONObject("responseData");
            ja = json.getJSONArray("results");

            int resultCount = ja.length();

            for (int i =0; i<resultCount; i++)
            {
                JSONObject resultObject = ja.getJSONObject(i);
                result = resultObject.toString();

            }

        }
        catch(Exception ex)
        {
            //responsetxt.setText(ex.getMessage());
        }
    }
Posted

1 solution

It's waiting for the response. Does the client answer?
 
Share this answer
 
Comments
adnama 2-Nov-11 5:55am    
Yes it's supposed to. When I use the url on a browser it sends the message and you get a string in return, but this doesn't do anything.
akosidab 24-May-12 3:26am    
Hi adnama,

Have you solved this issue?

I have the same problem returning a null in the httpClient.execute()

I have been looking for answers in the web but i cannot find one.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900