I am trying to connect through HttpPost and send the username and password to the website, and then get the string from this website. I tried various methods that worked for me in the past, but now when I submit the username and password identifiers, the application expires up to 4 minutes and then throws the following exception:
07-16 16:32:32.897: W/System.err(632): Unable to connect to the server 07-16 16:32:32.907: W/System.err(632): org.apache.http.conn.HttpHostConnectException: Connection to http://devdashboard.company refused 07-16 16:32:32.917: W/System.err(632): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:183) 07-16 16:32:32.917: W/System.err(632): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) 07-16 16:32:32.917: W/System.err(632): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119) 07-16 16:32:32.917: W/System.err(632): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360) 07-16 16:32:32.917: W/System.err(632): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555) 07-16 16:32:32.917: W/System.err(632): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487) 07-16 16:32:32.927: W/System.err(632): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465) 07-16 16:32:32.927: W/System.err(632): at company.android.dashboard.app.HttpHelperAndroid.sendToHttp(HttpHelperAndroid.java:66) 07-16 16:32:32.927: W/System.err(632): at company.android.dashboard.app.DashboardAppActivity.goToDashboard(DashboardAppActivity.java:62) 07-16 16:32:32.927: W/System.err(632): at java.lang.reflect.Method.invokeNative(Native Method) 07-16 16:32:32.937: W/System.err(632): at java.lang.reflect.Method.invoke(Method.java:511) 07-16 16:32:32.937: W/System.err(632): at android.view.View$1.onClick(View.java:3039) 07-16 16:32:32.947: W/System.err(632): at android.view.View.performClick(View.java:3511) 07-16 16:32:32.947: W/System.err(632): at android.view.View$PerformClick.run(View.java:14105) 07-16 16:32:32.947: W/System.err(632): at android.os.Handler.handleCallback(Handler.java:605) 07-16 16:32:32.957: W/System.err(632): at android.os.Handler.dispatchMessage(Handler.java:92) 07-16 16:32:32.957: W/System.err(632): at android.os.Looper.loop(Looper.java:137) 07-16 16:32:32.967: W/System.err(632): at android.app.ActivityThread.main(ActivityThread.java:4424) 07-16 16:32:32.977: W/System.err(632): at java.lang.reflect.Method.invokeNative(Native Method) 07-16 16:32:32.977: W/System.err(632): at java.lang.reflect.Method.invoke(Method.java:511) 07-16 16:32:32.977: W/System.err(632): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 07-16 16:32:32.987: W/System.err(632): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 07-16 16:32:32.987: W/System.err(632): at dalvik.system.NativeStart.main(Native Method) 07-16 16:32:32.987: W/System.err(632): Caused by: java.net.ConnectException: failed to connect to /50.19.240.232 (port 80): connect failed: ETIMEDOUT (Connection timed out) 07-16 16:32:32.997: W/System.err(632): at libcore.io.IoBridge.connect(IoBridge.java:114) 07-16 16:32:32.997: W/System.err(632): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192) 07-16 16:32:32.997: W/System.err(632): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459) 07-16 16:32:33.007: W/System.err(632): at java.net.Socket.connect(Socket.java:842) 07-16 16:32:33.007: W/System.err(632): at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119) 07-16 16:32:33.017: W/System.err(632): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144) 07-16 16:32:33.017: W/System.err(632): ... 22 more 07-16 16:32:33.027: W/System.err(632): Caused by: libcore.io.ErrnoException: connect failed: ETIMEDOUT (Connection timed out) 07-16 16:32:33.047: W/System.err(632): at libcore.io.Posix.connect(Native Method) 07-16 16:32:33.047: W/System.err(632): at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:85) 07-16 16:32:33.047: W/System.err(632): at libcore.io.IoBridge.connectErrno(IoBridge.java:127) 07-16 16:32:33.057: W/System.err(632): at libcore.io.IoBridge.connect(IoBridge.java:112) 07-1 6 16:32:33.057: W/System.err(632): ... 27 more
Internet access permission is included in the XML manifest file
My current implementation is as follows:
String LOGIN = " email@gmail.com "; String PASSWORD ="password1"; //JSONObject to send the username and pw JSONObject json = new JSONObject(); //put the path in the JSONArray object JSONArray vect = new JSONArray(); vect.put("company Android Library"); vect.put("Rocket Ship"); int duration = 50; try { json.put("email", LOGIN); json.put("password", PASSWORD); json.put("json", "true"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } Log.d(TAG, "ABOUT TO SEND:" + json.toString()); JSONObject inJson = HttpHelperAndroid.sendToHttp(json, "http://devdashboard.company/login"); if(inJson != null) { Log.d(TAG, "RECIEVED the JSON:" + inJson.toString()); } else Log.d(TAG, "THE RESPONSE WAS NULL"); }
And the HttpHelperAndroid class looks like this:
public class HttpHelperAndroid { private static final String TAG = "HttpHelperAndroid";
And here is my XML just for kicks:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="company.android.dashboard.app" android:versionCode="1" android:versionName="1.0" > <uses-permission android:name="android.permission.INTERNET" /> <uses-sdk android:minSdkVersion="7" /> <application android:icon="@drawable/company_android_ico" android:label="@string/app_name" > <activity android:name=".DashboardAppActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
I used the HttpHelper class in past projects, and it worked for me, in addition, I tried to implement this with nameValuePairs:
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair("email", " email@gmail.com ")); nameValuePairs.add(new BasicNameValuePair("password", "password1")); nameValuePairs.add(new BasicNameValuePair("json", "true")); try { httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
And it gave the same result.
Could this somehow become a certificate? or maybe something related to the damaged XML file (I tried to redo the project and the xml file) Android HTTP Connection refused Or maybe there is some kind of problem with the Android files?
I am open to any suggestions!
I studied this because of the large number of angles, and I am happy to provide any other information that would be useful! I really appreciate your time!
NOTE. . The url is a dummy url, not the actual one I'm connecting to for security reasons. I can twist the actual website from the command line with the parameters, and it works, and I can also log in normally from a web browser.
EDIT I have identified the problem! But not unfortunately. Therefore, the problem is that I am using the URL of a dev server that does not have a domain entry on the global DNS server. Therefore, to fix this, I somehow need to edit the hosts file on my Android device / in the emulator ... does anyone know how to do this legally?