好的..这很奇怪。我正在尝试在android中发出http请求。它可以工作,我可以使用 StringWriter“构建”一个字符串,但代码在 writer.toString() 处引发异常。如果我使用 StringBuilder 或 StringWriter 没有区别。
try {
HttpResponse response = httpClient.execute(httpPost);
InputStream is = response.getEntity().getContent();
StringBuilder writer = new StringBuilder();
//StringWriter writer = new StringWriter();
int ch;
while(( ch = is.read()) != -1) {
writer.append((char)ch);
}
String theString = writer.toString();
return theString;
}
catch (Exception e) {
return e.getMessage();
}
有任何想法吗?