Timeout when making HTTPS requests in Android Emulator - android

I'm trying to make HTTPS request using the HttpURLConnection class. When the URL starts with "http://" the connection responds as expected after calling .connect(). The problem is when the URL starts with "https://", the connection always times out (after 5000ms, the timeout I set). The exception message is:
failed to connect to [url] (port [XXX]) after 5000ms
I'm using the Parse SDK for Android and every query I make times out as well. The exception message is:
com.parse.ParseRequest$ParseRequestException: i/o failure
and
org.apache.http.conn.ConnectTimeoutException: Connect to /54.84.111.80:443 timed out".
So I think the Parse SDK always uses HTTPs behind the hood.
Some things I think I need to point out:
I'm using the emulator with the Android 5.1.1 x86_64.
The internet I'm using has a proxy and the emulator is being started with the -http-proxy command line option.
I can't deactivate this proxy because I'm using the internet of the company I work for.
I have an application written in .NET that uses the Parse SDK as well, and it runs fine using the same internet connection.

<uses-permission android:name="android.permission.INTERNET"/>
try using this tag instead of
<permission android:name="android.permission.INTERNET"></permission>
if the problem still persists then it could be proxy problem

Related

It is impossible to create a new session because 'createSession' which takes HttpClient, InputStream and long was not found or it is not accessible

I am getting the error "It is impossible to create a new session because 'createSession' which takes HttpClient, InputStream and long was not found or it is not accessible"
also my Appium server gets killed autometically after this error in console.
Please help to resolve.
The error may occurs from various reason. You need to check your appium server log to know the exact cause. Beside that you can verify following.
Start your appium server in session-override option.
Make sure your appium server is running.
Make sure your are using correct url of appium server.
Confirm your device is properly connecting to the laptop. You can verify it by using adb devices command (for android). Make sure it is showing only one device.
Make sure your DesiredCapabilities are correct or all required desired capabilities are included.
Try re-starting the appium server.

Volley + OkHttp on Android gives error on status 200 response

When I make my request with only Volley everything goes well and my StringRequest goes to onResponse.
But when I switch to Volley + Okhttp combination, my request goes through, I receive the same response as before but then I get the following error message:
E/Volley﹕ [122319] BasicNetwork.performRequest: Unexpected response code 200 for <my request url>
java.io.IOException: closed
com.android.volley.NetworkError: java.io.IOException: closed
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:182)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:114)
Caused by: java.io.IOException: closed
at okio.RealBufferedSource$1.read(RealBufferedSource.java:345)
at java.io.InputStream.read(InputStream.java:162)
at com.android.volley.toolbox.BasicNetwork.entityToBytes(BasicNetwork.java:254)
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:130)
            at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:114)
Im using this https://gist.github.com/bryanstern/4e8f1cb5a8e14c202750 for my OkHttpStack for Volley.
I haven't had too much time to investigate but I was running into the same issue when using the emulator connected through a proxy (Charles). For me the problem goes away when I test without a proxy or on device.
This exact same problem happened to me when using the start and stop methods of the RequestQueue. It was pointed out in many popular blogs that the RequestQueue should be stopped when user is flinging to ensure there's no jerking. However when you call stop, all RequestQueue's requests are stopped, even the ones which were already doing network call. The above exception happened when these requests are stopped preliminarily. Not calling the stop function solved the problem for me.
For those people using a Proxy (in my case Charles) besides configuring your proxy in Settings it is necessary to configure also your proxy in the Android Emulator.
So, here is my configuration in Settings Emulator
And this are the steps to configure the proxy using wifi in Android Emulator
Settings
Network & Internet
Wi-Fi
Android Wifi
Click on Setting icon
Click Edit icon
Configure your proxy

Google cloud messaging GCM through proxy

I am having trouble sending a message to a device through the company proxy.
I have done the GCM tutorial on the google site and have successfully registered a device on the google servers with the android emulator,
and also on the server at my end.
For this I had to go through the company proxy, setting it in the access point of the emulator.
Now the problem I have is sending a message from my server to the device through the same proxy.
I am using the servlet code from the demo which uses the
com.google.android.gcm.server.Sender
helper class to send the message.
I am running the servlets on tomcat 7.
I have tried setting the proxy up in the catalina.properties file like so.
http.proxyHost=proxy.company.com
http.proxyPort=8080
And I have tried setting properties inside the servlet itself like below.
System.setProperty("http.proxyHost", "proxy.company.com");
System.setProperty("http.proxyPort", "8080");
But still I get the timeout.
I know its the company proxy because I got the messaging working at home where I have no proxy.
I have seen a proxy object created in the java code and then a connection created with it, but I dont think that is usable here since I am using Sender helper class to send the message.
This is the line that fails in a timeout.
Result result = sender.send(message, registrationId, 5);
Any help would be appreciated.
Regards
Bill
Alright, I finally have it working. In my comment I mentioned that I had succeeded in sending out the message, but the emulator was not recieving it. I had forgotten to follow my own earlier advice and run the emulator from the command line with the proxy parameters set like so:
emulator.exe -avd avd22google -http-proxy proxy.company.com:8080 -debug-proxy
So to summarise, my initial problem was that I had registered the emulator on the with GCM and with my local server, but the when I clicked send message I was getting a timeout.
I initially thought it was the firewall so I did some research and set up the proxy in tomcats catalina.properties file.
This made no difference.
I used the "Charles" web proxy debugger software to see where the message was attempting to be sent to and it came up with https://android.googleapis.com:443
So I initially I added the following to my catalina.properties file:
https.proxyHost=proxy.company.com
https.proxyPort=443
It still did not work. A colleague of mine told me that our company proxy handles all types of requests through port 8080, so I changed the the poort line to:
https.proxyPort=8080
This allowed the message to be sent out.
But then the message was not getting through to the emulator and I was receiving the following error in LogCat.
[GTalkConnection.12] doConnect: caught XMPPError connecting to mtalk.google.com:5228.: -- caused by: java.net.SocketException: The operation timed out
Then I remembered that you need to start the emulator with the command line to get it to use the proxy. Once I did this a flood of messages appeared on my emulator!
So I finally have it working end to end. It's taken me about a week to get GCM fully working within my company firewall, so hopefully this post can help some other poor sod doing this in the future.
cheers
Bill

Android Unknown Host Exception (DNS Problem) !

i'm trying to connect to the server from my android device in order to get XML inputStream to do that i'm using XmlPullParser
my server Url is:
http://www.biat.com.tn
so, when i'm trying to get the inputstream from this url, I'm getting an unknown host Exception, the screen become black... (although it works for me in localhost)
Then, to check my config I tried to ping the server from the ADB shell, but there is no connection established !!!
I check an other server (http://www.topnet.tn), but i faced the same problem.
PS : I'm getting Streams from these URLs in Navigator
I think that .TN (Tunisia) domain name are not known by Android devices !!!!
i googled this problem and I found a solution, that i should lauch my application in -dns-server mode with putting 8.8.8.8 as dns server... so it works
but pinging my URL server does not !!! please any one can understand this problem !!!
please help...
How are you loading the data? URLConnection, HttpClient?
http://www.biat.com.tn does http 302 redirect to http://www.biat.com.tn/biat/.
In most cases you will need to handle redirect in your code.

Network Connection

I am trying to call a webservice from an android app (Testing from an Emulator)
Now, i keep on getting "request time failed : java.net.SocketConnection : Address family not supported by protocol"
So, went to 'Browser' app of Android-Emulator and wasn't able to open any website
Also, then wrote a java code (J2SE) for network connection and got a "java.net.ConnectException: Connection timed out: connect"
Then looked here and there and guys had a say that some setting are to be done in eclipse and android-emulator to get the network connection going
Like in one of messages here --> "http://192.9.162.102/thread.jspa?messageID=10631928"
But how and where is what i am looking for ?
Any suggestions ?
Thanks
Yogurt
put this line<uses-permission android:name="android.permission.INTERNET"></uses-permission> in Manifest.xml file. I think it will work for u.

Categories

Resources