使用适用于Android的Java获取其余的Web服务 [英] Get response rest web services Using Java for Android

查看:67
本文介绍了使用适用于Android的Java获取其余的Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码是我按照有关Web服务的教程制作的,尽管没有给出错误,但是什么也没有发生.谁能帮我吗?因为我无法继续.我需要连接到Web服务,但无法正常工作.

使用调试器,我发现它正在此特定行的第一种方法中停止:

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:

HttpResponse response = client.execute(request);



这是我的代码:



This is my code:

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());
        }
    }

推荐答案

正在等待响应.客户会回答吗?
It''s waiting for the response. Does the client answer?


这篇关于使用适用于Android的Java获取其余的Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆