[android-developers] Re: HTTPS POST problem

2011-01-07 Thread DanH
Note that if a request goes through once and the identical request
doesn't show up on the server when issued a second time it's likely
because somewhere along the way the response is being served out of a
cache.

On Jan 6, 6:52 am, Filiz Gökçe  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");
>
>                           

Re: [android-developers] Re: HTTPS POST problem

2011-01-06 Thread Vo Trung Liem
Hello,

You can reconnect when the connect sucessed.

Best regards,
Liem Vo.

On Thu, Jan 6, 2011 at 11:43 PM, Filiz Gökçe  wrote:

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

Re: [android-developers] Re: HTTPS POST problem

2011-01-06 Thread Filiz Gökçe
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  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  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();
> >
> > }
> >
> >

[android-developers] Re: HTTPS POST problem

2011-01-06 Thread Brill Pappin
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  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
>
>                              ou