When Android downloads a file from the Web server, connection refused appears.

Source: Internet
Author: User

Android applicationsProgramYou can use the getinputstream () method of httpurlconnection to access files on the web server. However, during debugging, I always prompt a connection refused exception. Then I analyzed it carefully:

The URL of the server file to be downloaded is http: // localhost: 8080/mp3player/resources. XML. Because my mobile phone is connected to my computer via USB, I initially thought that my mobile phone could access my computer's web programs, but this is obviously incorrect. Because the mobile phone is connected to the router through WiFi (the router does not distinguish whether the current connected device is a mobile phone or a computer), http: // localhost: 8080/mp3player/resources is used. xml url, the program will search for the web program on the mobile phone, apparently there is no web program on the mobile phone. Therefore, the correct method is to use the IP address of the computer as the URL, so the correct URL should be: http: // 192.168.1.100: 8080/mp3player/resources. XML, which is passed the test. Remember.

Related Article

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.