Reputation: 1968
I got and SSLHandshakeException when I use synchronized connection to an HTTPS server. If I use asynchronized connection to same url I can't get two differentes answer:
Case 1: If I call the asynchronized request directly from main thread I got an 403 forbidden and empty response body.
Case 2: If I call the asynchronized request from a AsyncTask that had been called from main I got an 200 and the right response body that I am expecting.
So my question, why will the synchronized requested fail, and why I have to call the asynchronized request through an AsyncTask to get the expected answer?
UPDATE Looks like the problem with calling synchronous request inside the AsyncTask is that the Authenticator to OKHttp client is not done setting the Authenticator, therefor I am getting the Handshake Exception.
LAST UPDATE Got it to work. Refactored the posting string. From just getting the toString of a map to creating a JSONObject. Somehow, the authorization then passed and it wasn't even necessary to increased the timeout.
Upvotes: 1
Views: 694
Reputation: 3083
As far as I understood, the problem is making a request form the main thread.
If you read:
How to fix android.os.NetworkOnMainThreadException?.
You will understand that you cannot make network requests from the Ui thread(since Api 11 I think).
EDIT
Check google page:
http://developer.android.com/training/basics/network-ops/connecting.html.
EDIT 2
If the request is asynchronous, e.g using OKHttp async way, then the problem might come from the fact that you have a small timeout, I usually set it to 3-5 seconds(I had this problem).
Upvotes: 2