-3

当我尝试运行一些代码时,我收到以下错误:

The method parse() is undefined for the type HttpResponse

这是我的代码:

post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = client.execute(post);
strResp = EntityUtils.toString(response.getEntity());
Document document = response.parse();
4

3 回答 3

1

没有这样parse()的方法HttpResponse

于 2013-09-11T14:24:29.150 回答
0

我认为您应该从中获得一些解决方案:How to parse a xml type HTTPResponse in Android

大概是这样的:

...
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = client.execute(post);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputStream is = response.getEntity().getContent();
Document doc = db.parse(is);
于 2013-09-11T14:28:40.690 回答
0

为什么要解析 HttpResponse ?它不存在...为字符串解析存在也许你想做:

Document document = strResp.parse();

如果 strResp 是一个字符串,这将起作用。但也许这不是你想要的。

我这样做(我在网上找到了它,它对我来说非常有效):

    public String getXmlFromUrlHttp(String url)  
{
    String xml = null;

    try {
        // defaultHttpClient            
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpGet httpPost = new HttpGet(url);
        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        xml = EntityUtils.toString(httpEntity);

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return xml;
}

然后你解析函数的结果;)

于 2013-09-11T14:27:32.027 回答