We start to use, Post but the same problem still continue. Some time we can catch the response, sometimes we couldnt connect server. All parameters are true.
Filiz Gökçe On 6 January 2011 17:55, Brill Pappin <[email protected]> wrote: > You may have a problem with param encoding. > Also note that you should not have to specify ay https classes, if > done properly the client will switch to https as needed. > > Unless you really need a GET it also might be better to use a POST. > > I keep meaning to move my http client code into a library, but i > haven't yet so its not easy to send you some quick code, hoever if you > look thought the samples, you will find several implementations that > work well. > > - Brill Pappin > > On Jan 6, 7:52 am, 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]> > 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

