当我尝试运行某些代码时,我收到以下错误:
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();
答案 0 :(得分:1)
parse()
HttpResponse
答案 1 :(得分:0)
为什么要解析HttpResponse? 它不存在......对于String存在Parse 也许你想做:
Document document = strResp.parse();
如果strResp是一个String,那将会有效。但也许这不是你想要的。
我是这样做的(我在网上找到了它,它对我来说很完美):
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;
}
然后解析函数的结果;)
答案 2 :(得分: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);