org.apache.http.conn.HttpHostConnectException: Connection to http://localhost refused in android

后端 未结 13 1707
一向
一向 2020-12-02 20:42

I am making an application that uploads images to server and updates its database to server in android while executing it, it shows an error

Connection to ht         


        
相关标签:
13条回答
  • 2020-12-02 21:09

    Two solutions for this error:

    1. add this permission in your androidManifest.xml of your Android project

    <uses-permission android:name="android.permission.INTERNET"/>
    

    2. Turn on the Internet Connection of your device first.

    0 讨论(0)
  • 2020-12-02 21:10

    i was facing exactly the same issue and i made following changes to my URL after which it was working perfectly fine..

    From:

    http://localhost/Image4android/get_all_images.php
    

    To:

    http://192.168.1.2/Image4android/get_all_images.php
    
    where the ip: 192.168.1.2 is IPv4 address. In windows Run > CMD > Ipconfig
    
    0 讨论(0)
  • 2020-12-02 21:13

    I am using PHP for webservice and Android 4.x. device for connecting to the webservice. I had similar problem where, using 10.0.2.2 worked well with emulator but failed to connect from device. The solution that worked for me is: Find IP of your computer ... say 192.168.0.103 Find the port of your apache ... say 8080 Now open httpd.conf and locate following line Listen 127.0.0.1:8080 After this line add following Listen 192.168.0.103:8080 Thats it. Now if you use 192.168.0.103:8080 in your android code, it will connect!!

    0 讨论(0)
  • 2020-12-02 21:20

    if you are using emulator to run your app for local server. mention the local ipas 10.0.2.2 and have to give Internet permission into your app :

    <uses-permission  android:name="android.permission.INTERNET" />
    
    0 讨论(0)
  • 2020-12-02 21:21

    When you test with device you want to add your PC ip address.

    in pc run in cmd Ipconfig

    in ubuntu run terminal ifconfig

    Then use "http://your_pc_ip_address:8080/register" insted of using "http://10.0.2.2:8080/register"

    in my pc = 192.168.1.3
    

    and also add internet permission to Manifest

    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    
    0 讨论(0)
  • 2020-12-02 21:25

    try adding the permission outside the application tag of the manifest in addition to the above mentioned answers of changing localhost to 10.0.2.2:8080

    0 讨论(0)
提交回复
热议问题