I think I found why this protocol error occurs. It seems the problem are
indeed the redirects, but only when there are redirects that go from HTTPS
to HTTP. In fact I tried also that same code with url https://www.google.com,
and it gave the same error (it was redirecting to http://www.google.com).

To disable the automatic redirect following I used:
HttpsURLConnection.setFollowRedirects(false);  // for HTTPS requests
HttpURLConnection.setFollowRedirects(false);  // for HTTP requests

Now I have to find out how to read the http/s response headers from the
URLConnection, to get the "location" field. (if someone already knows
that.....telll meeee :D:D).


Ciao!
Yuvi

On Tue, Jan 26, 2010 at 9:52 PM, Jason Proctor <
[email protected]> wrote:

> well this does seem to point to a long initialisation period for the Apache
> library. i don't have anything informed to suggest on the protocol error -
> maybe the Apache library supports more SSL protocols than the regular Java
> network library? dunno. checking versions etc couldn't hurt.
>
> there's a bunch of redirects going on with that https://mip.sunrise.chURL, 
> btw. something somewhere might be falling over that.
>
> hth
>
>
>  Yeah probably it has something to do with all the initialization stuff...I
>> just tried *not* using the Apache HttpClient, with the following code:
>>
>> String myHttpsUrl = "<https://mip.sunrise.ch/>https://mip.sunrise.ch";;
>>
>> URL url = new URL(myHttpsUrl);
>> URLConnection urlConnection = url.openConnection();
>>
>> BufferedReader br = new BufferedReader(new
>> InputStreamReader(ucon.getInputStream()));
>> String line;
>> StringBuilder htmlContent = new StringBuilder();
>> while ((line = br.readLine()) != null) {
>>    htmlContent.append(line);
>> }
>>
>> (I'm reading the whole content just to make sure my request has been
>> executed and fetched..).
>>
>> Anyway....it seems much faster!! (first request around 2 seconds, compared
>> to the HttpClient's 6, 10 or 20 seconds).
>>
>> However there is a problem: with the current https url it actually doesn't
>> work (it worked for other https addresses). I get back the following error
>> (with the url "<https://mip.sunrise.ch/>https://mip.sunrise.ch";):
>>
>>
>> java.io.IOException: SSL handshake failure: Failure in SSL library,
>> usually a protocol error
>> error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol
>> (external/openssl/ssl/s23_clnt.c:585 0xaf589f78:0x00000000)
>>    at
>> org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.nativeconnect(Native
>> Method)
>>    at
>> org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:308)
>>    at
>> org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.getSecureSocket(HttpConnection.java:173)
>>    at
>> org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnection$HttpsEngine.connect(HttpsURLConnection.java:408)
>>    at
>> org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.sendRequest(HttpURLConnection.java:1227)
>>    at
>> org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.doRequestInternal(HttpURLConnection.java:1554)
>>    at
>> org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.doRequest(HttpURLConnection.java:1547)
>>    at
>> org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1055)
>>    at
>> org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnection.getInputStream(HttpsURLConnection.java:257)
>>
>> It seems like an ssl version error...mmmm....
>> Maybe I have to specify explicitly this version somewhere? Or maybe some
>> certificates? :S
>>
>> If anyone has an idea please let me know :)
>>
>>
>> Thanks everyone!
>> Yuvi
>>
>> ....
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to