我遇到了下一个问题,我有一个 xml 网络服务只包含一个字符串示例:您输入了 Invalis 数据,我想将此字符串读入我的应用程序。我的代码运行良好,但突然开始返回一个 html 代码,而不是我想要的字符串 :( 这是我的代码:
try {
String xx;
DefaultHttpClient httpClient = new DefaultHttpClient();
;
HttpGet httpPost = new HttpGet(urlString);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
inputStream = httpEntity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"),
8);
StringBuilder stringBuilder = new StringBuilder();
String line = null;
if ((line = reader.readLine()) != null) {
stringBuilder.append(line + "\n");
xx = stringBuilder.toString();
}
inputStream.close();
}
catch (UnsupportedEncodingException e) {
System.err.print("UnsupportedEncodingException: " + e);
}
catch (ClientProtocolException e) {
System.err.print("ClientProtocolException: " + e);
}
catch (IOException e) {
System.err.print("IOException: " + e);
}
如果有人可以提供帮助,请!