HttpHostConnectException: Connection refused Android

前端 未结 5 733
礼貌的吻别
礼貌的吻别 2021-02-09 14:53

I am trying to connect via HttpPost and send a username and password to a website and then receive a string from that website. I have tried various methods that have worked for

相关标签:
5条回答
  • 2021-02-09 15:20

    I have identified the problem! So the issue is that I am using a dev server url that doesn't have a domain entry on the global DNS server.

    So there are two possible solutions to this issue:

    1) Editing the hosts file on the Android device (requires rooting your phone): How to change the hosts file on android

    2) Getting the server registered on the global DNS server. (also hard to do if you're not responsible for the url)

    Anyways I hope this helps someone else too!

    0 讨论(0)
  • 2021-02-09 15:23

    Please follow these solution may be among these one solve your issue.

    1> check your manifest file internet permission there or not.

    2> check your url with browser by rest client and pass the appropriate request.

    3> open the url in mobile like:- http://your ip address/port that's it just for checking do you have a permission or not to open this url in mobile.

    0 讨论(0)
  • 2021-02-09 15:27

    This post is old, but it is the first result when googling this error. I encountered the same exception, and everything was completely correct in my code. I commented out the line containing the INTERNET permission in my AndroidManifest.xml, ran the app, clicked/tapped my button to send the HTTP request and get the exception, closed the app, went back to the manifest, uncommented the permission line, ran the app again, and the exception was resolved!

    This kind of bugs in 2015 (and in "advanced" tools like the latest compile tools for Android API 21, and Intellij IDEA 14) drives me mad! You are approaching your deadline, and this sort of bugs completely disrupts your work!

    0 讨论(0)
  • 2021-02-09 15:32

    The problem is in wifi sleeping. Please use

    WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL , "MyWifiLock");
    wifiLock.acquire();
    

    and permission:

    uses-permission android:name="android.permission.WAKE_LOCK";
    
    0 讨论(0)
  • 2021-02-09 15:33

    There are a few possibilities

    1) the url is incorrect "http://devdashboard.company/login" is not right. At least check in browser. ping the host as well.

    2) This should be an https connection instead.

    3) there is some certification required.

    4) You are missing a port number. or domain has not been setup correctly. perhaps port 80 the default is incorrect?

    5) the call should not be a post.

    In general you are either responsible for the server or you are not. It appears that it is some elses responsibility, and you should ask them what the correct url and parameters are. So its probably no ones fault, but you need to ask them about the connection to verify.

    The other thing you can do is to try and see what the url looks like in an application that is succesfully connectiing. take a look that this.

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