Я анализирую файл rss.xml, используя анализ DOM в Android.При разборе документа, используя InputStream
из URL, я получаю IOException
.Что вызывает это?
public static Document postPage(String url, String data ,boolean isPost) {
String ret = null;
HttpResponse response = null;
BasicHttpContext localContext = null;
DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
HttpPost httpPost = null ;
HttpGet request = null;
if(Constants.LOG)Log.d("URL in util is : ",""+url);
httpClient.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),new UsernamePasswordCredentials(Constants.AUTHENTICATION_USERNAME, Constants.AUTHENTICATION_PASSWORD));
if(Constants.LOG)Log.d("In Http get", "URL is : "+url);
request = new HttpGet();
try {
request.setURI(new URI(url));
response = httpClient.execute(request);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
if(Constants.LOG)Log.d("ClientProtocolException", ""+e);
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
if(Constants.LOG)Log.d("IOException", ""+e);
e.printStackTrace();
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
if(Constants.LOG)Log.d("URISyntaxException", ""+e);
e.printStackTrace();
}
try {
response = httpClient.execute(request);
}
} catch (ClientProtocolException e) {
if(Constants.LOG)Log.d("UTIL", "postPage ClientProtocolException Ex::"+e);
return null;
} catch (IOException e) {
if(Constants.LOG)Log.d("UTIL", "postPage IOException Ex::"+e);
return null;
}
ret = response.getStatusLine().toString();
if(Constants.LOG)Log.d("UTIL", "postPage STATUS::"+ret);
HttpEntity he = response.getEntity();
InputStream inStream = null;
Document docElement = null;;
DocumentBuilderFactory docBuilderFactory = null;
DocumentBuilder docBuilder = null;
try {
URL Url = new URL(url);
inStream =he.getContent();
docBuilderFactory =DocumentBuilderFactory.newInstance();
docBuilder = docBuilderFactory.newDocumentBuilder();
docElement = docBuilder.parse(inStream);
if(Constants.LOG)Log.d("UTIL", "isStream available::"+inStream.available());
} catch (IOException e) {
// TODO Auto-generated catch block
if(Constants.LOG)Log.d("UTIL", "postPage IOException1 Ex::"+e);
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
inStream.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return docElement;
}
Я получаю исключение по адресу:
docElement = docBuilder.parse(inStream);