【发布时间】:2014-06-10 08:37:09
【问题描述】:
当我的 api 级别设置为 8 时,一切正常。但是当我尝试将 minSdkVersion 设置为 11 时,我获取 xml 的 http 请求不起作用。我在 if 上有一个例外。 代码如下:
URL url;
String ciao="";
try {
url = new URL("myurl");
URLConnection connection = url.openConnection();
HttpURLConnection httpConnection = (HttpURLConnection)connection;
int responseCode = httpConnection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
InputStream in = httpConnection.getInputStream();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document dom = db.parse(in);
DOMSource domSource = new DOMSource(dom);
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.transform(domSource, result);
ciao=writer.toString();
}
}
catch(Exception e)
{
}
return ciao;
【问题讨论】:
-
你得到了什么异常?
-
发布日志猫。尝试清理项目。
-
你永远不会在 if 上遇到异常。也许在它之上。你在主线吗?在 API 11+ 中,这不再合法。
标签: android api httprequest