参数通过httpgetClient传递

时间:2012-10-15 11:34:13

标签: apache-httpclient-4.x

我需要点击URL并获得响应,但是通过这种方法,我只能获得一条消息,而我想传递多个值作为响应。

以下是方法:

public String getOutputFromUrl(String url) 
    {
        Log.d("in getOutputFromUrl", "getOutputFromUrl");
        String[] output = null;
        try {
            httpClient = new DefaultHttpClient();
            httpGet = new HttpGet(url);
            httpResponse = httpClient.execute(httpGet);
            httpEntity = httpResponse.getEntity();
            output = EntityUtils.toString(httpEntity);
        } catch (UnsupportedEncodingException e) {
            Log.d("in UnsupportedEncodingException", e.toString());
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            Log.d("in geClientProtocolExceptiontOutputFromUrl",  e.toString());
            e.printStackTrace();
        } catch (IOException e) {
            Log.d("in getOutputFromUrl", e.toString());
            e.printStackTrace();
        }
        Log.d("in getOutputFromUrl:output===>>", output);

        return output;
     }

我希望方法的返回类型是String []或任何类的对象,但是

 output = EntityUtils.toString(httpEntity)

这一行只接受一个字符串;没有其他对象或字符串数​​组,所以我不能在此输出变量中保留多个值作为来自URL链接的响应

0 个答案:

没有答案