About the java.io.EOFException problem of accessing XML via Java HttpURLConnection in Android development

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.