If you can reliably reproduce this, preferably in the emulator, use
WireShark or any other network dump tool to see what goes on at the tcp/ip
level.

--
Kostya Vasilyev -- http://kmansoft.wordpress.com
06.01.2011 17:04 пользователь "Filiz Gökçe" <[email protected]> написал:
> There is no exception in both cases.
> Generally we get proper response for the first time but null response in
the
> second time eventhough we are tying to post same url and same parameters.
>
> Filiz Gökçe
>
>
>
>
> On 6 January 2011 15:13, Kumar Bibek <[email protected]> wrote:
>
>> Something on the logs? What exception are you getting?
>>
>> Kumar Bibek
>> http://techdroid.kbeanie.com
>> http://www.kbeanie.com
>>
>>
>>
>> On Thu, Jan 6, 2011 at 6:22 PM, Filiz Gökçe <[email protected]>
wrote:
>>
>>> Hi,
>>> I try to connect the https connection.
>>>
>>> The below source is working but not stable.
>>>
>>> Sometimes same url+parameters results in a proper way, sometimes nothing
>>> comes as a response. We also looked at the logs of server, when results
are
>>> null, there seems no requests from the server.
>>>
>>> I really couldn’t understand the reason of this kind of behavior. Method
>>> same, url is same, parameters are same but connection is one time
successful
>>> and one time failure.
>>>
>>> I tested 1.6, 2.1 and 2.2 and nothing changed. Do you know anything
about
>>> SSL connections in Android. Is there any bug? You are my last chance.
>>>
>>>
>>>
>>> *public* *static* String postURL(String url)
>>>
>>> {
>>>
>>> String result = "";
>>>
>>> String url2 = "";
>>>
>>> String param = "";
>>>
>>>
>>>
>>> String[] *keys* = *null*;
>>>
>>> url2 = url.substring(0, url.indexOf("?"));
>>>
>>> param = url.substring(url.indexOf(url2) + url2.length() + 1);
>>> //
>>>
>>>
>>>
>>> *try*
>>>
>>> {
>>>
>>> System.*out*.println("SSL URL " + url2 + " & param: " +
>>> param);
>>>
>>> PrintWriter outWriter = *null*;
>>>
>>> BufferedReader inReader = *null*;
>>>
>>> HttpsURLConnection ucon = *null*;
>>>
>>> StringBuffer parameter = *new* StringBuffer();
>>>
>>> parameter.append(param);
>>>
>>>
>>>
>>> String operatorAddress = *new* String(url2);
>>>
>>> *try*
>>>
>>> {
>>>
>>>
>>>
>>> HostnameVerifier hv = *new* HostnameVerifier()
>>>
>>> {
>>>
>>> @Override
>>>
>>> *public* *boolean* verify(String
>>> urlHostName, SSLSession session)
>>>
>>> {
>>>
>>> System.*out*.println("Warning: URL
>>> Host: " + urlHostName + " vs. " + session.getPeerHost());
>>>
>>> *return* *true*;
>>>
>>> }
>>>
>>>
>>>
>>> };
>>>
>>> // Create a trust manager that does not validate
>>> certificate
>>>
>>> // chains
>>>
>>> TrustManager[] trustAllCerts = *new*TrustManager[] {
>>> *new* X509TrustManager()
>>>
>>> {
>>>
>>> *public*java.security.cert.X509Certificate[] getAcceptedIssuers()
>>>
>>> {
>>>
>>> *return* *null*;
>>>
>>> }
>>>
>>>
>>>
>>> *public* *void*checkClientTrusted(java.security.cert.X509Certificate[]
certs, String
>>> authType)
>>>
>>> {
>>>
>>> }
>>>
>>>
>>>
>>> *public* *void*checkServerTrusted(java.security.cert.X509Certificate[]
certs, String
>>> authType)
>>>
>>> {
>>>
>>> }
>>>
>>> } };
>>>
>>>
>>>
>>> *try*
>>>
>>> {
>>>
>>> SSLContext sc = SSLContext.*getInstance*(
>>> "TLS");
>>>
>>> sc.init(*null*, trustAllCerts, *new*java.security.SecureRandom());
>>>
>>> HttpsURLConnection.*
>>> setDefaultSSLSocketFactory*(sc.getSocketFactory());
>>>
>>> HttpsURLConnection.*
>>> setDefaultHostnameVerifier*(hv);
>>>
>>>
>>>
>>> URL urlc = *new* URL(operatorAddress); //
>>> set URL
>>>
>>> ucon = (HttpsURLConnection)
>>> urlc.openConnection(); // open
>>>
>>> ucon.setHostnameVerifier(hv);
>>>
>>> }
>>>
>>> *catch* (Exception e)
>>>
>>> {
>>>
>>> System.*out*.println("CONNECTION EXCEPTION"
>>> );
>>>
>>> e.printStackTrace();
>>>
>>> }
>>>
>>> // *connetion*
>>>
>>> ucon.setDoOutput(*true*); // set output
>>>
>>> ucon.setDoInput(*true*); // set *intput*
>>>
>>>
>>>
>>> *try*
>>>
>>> {
>>>
>>> outWriter = *new*PrintWriter(ucon.getOutputStream()); //
>>> open
>>>
>>> // output
>>>
>>> // stream
>>>
>>> outWriter.print(parameter); // send data
>>>
>>> outWriter.close(); // close output stream
>>>
>>> }
>>>
>>> *catch* (Exception e)
>>>
>>> {
>>>
>>> System.*out*.println("OUTWRITER EXCEPTION");
>>>
>>> e.printStackTrace();
>>>
>>> }
>>>
>>>
>>>
>>> *try*
>>>
>>> {
>>>
>>> inReader = *new*
BufferedReader(*new*InputStreamReader(ucon.getInputStream())); //
>>> open
>>>
>>>
>>>
>>> // input
>>>
>>> // stream
>>>
>>> StringBuffer resultBuffer = *new*StringBuffer(
>>> ""); // result
>>>
>>> *while* ((result = inReader.readLine()) != *
>>> null*)
>>>
>>> resultBuffer.append(result);
>>>
>>> result = (resultBuffer.toString()).trim();
>>>
>>> inReader.close();
>>>
>>> }
>>>
>>> *catch* (Exception e)
>>>
>>> {
>>>
>>> System.*out*.println("INREADER EXCEPTION");
>>>
>>> e.printStackTrace();
>>>
>>> }
>>>
>>> System.*out*.println("RESULT ----" + result);
>>>
>>>
>>>
>>> }
>>>
>>> *catch* (Exception e)
>>>
>>> {
>>>
>>> *try*
>>>
>>> {
>>>
>>> *if* (inReader != *null*)
>>>
>>> inReader.close();
>>>
>>> *if* (outWriter != *null*)
>>>
>>> outWriter.close();
>>>
>>> }
>>>
>>> *catch* (IOException ex)
>>>
>>> {
>>>
>>> System.*out*.println("UTILITIES EXCEPTION 1"
>>> );
>>>
>>> e.printStackTrace();
>>>
>>> }
>>>
>>>
>>>
>>> }
>>>
>>> }
>>>
>>> *catch* (Exception e)
>>>
>>> {
>>>
>>> System.*out*.println("UTILITIES EXCEPTION 2");
>>>
>>> e.printStackTrace();
>>>
>>> }
>>>
>>> *return* result;
>>>
>>> }
>>>
>>>
>>>
>>> Thank you so much,
>>>
>>>
>>>
>>>
>>>
>>> Filiz Gökçe
>>>
>>>
>>> --
>>> 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]<android-developers%[email protected]>
<android-developers%[email protected]<android-developers%[email protected]>
>
>>> For more options, visit this group at
>>> http://groups.google.com/group/android-developers?hl=en
>>
>>
>> --
>> 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]<android-developers%[email protected]>
<android-developers%[email protected]<android-developers%[email protected]>
>
>> For more options, visit this group at
>> http://groups.google.com/group/android-developers?hl=en
>
> --
> 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]<android-developers%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
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