Just contact with Android development, try to write a small program familiar with, wrote a small program of the weather forecast, through the way of HttpURLConnection read stream to get the weather XML information provided by the network public interface. But in the establishment of the HTTP connection has been reported java.io.EOFException, many attempts have no, but the normal httpurlconnection can be accessed normally.
Through the query Baidu Big God, more is this is because httpurlconnection in some version of the Android platform exists bug problem, decisively change, by referring to httpclinet external package to solve the problem, very successful! The code is as follows:
//external weather API URL String URL= "Http://flash.weather.com.cn/wmaps/xml/china.xml"; HttpClient Client=Newdefaulthttpclient (); HttpGet HttpGet=Newhttpget (URL); HttpResponse Response=Client.execute (HttpGet); Httpentity Entity=response.getentity (); if(Entity! =NULL) {Entity=Newbufferedhttpentity (entity); InputStream is=entity.getcontent (); } BufferedReader=NewBufferedReader (NewInputStreamReader (IS));
About the java.io.EOFException problem of accessing XML via Java HttpURLConnection in Android development