Hill Hugo,
Nothing miss in your code. I had the same problem with you before when I got data from the server using HttpsURLConnection. And I try connect again that would be fine. If you find the reason, would you tell me? Thanks, Vu-Nguyen From: [email protected] [mailto:[email protected]] On Behalf Of Hugo Wang Sent: Wednesday, March 10, 2010 10:26 AM To: [email protected] Subject: [android-developers] query about the usage of HttpsURLConnection Hi all, I am using HttpsURLConnection to post data to a web server. Here is the function I wrote to get the result. (see the code below) Very strangely, when the function be first called in my program it would very likely return -1; and then I re-call the function after the first call, it would always work ok. So I wonder if there is anything I am missing in the code that when the function be firstly called, the missing party is be "initialized", in that the followed call goes OK. Could anyone give some hints on this? Here is my code of the function: ============= Public MyReturn executeHttpsGet(Context context, String url) { ................ try { URL u = new URL(url); HttpsURLConnection httpConnection; httpConnection = (HttpsURLConnection)u.openConnection(); httpConnection.setSSLSocketFactory(mSslContext.getSocketFactory()); httpConnection.setHostnameVerifier(mVerifier); httpConnection.setDoInput(true); httpConnection.setConnectTimeout(DEFAULTTIMEOUT); httpConnection.setUseCaches(true); httpConnection.connect(); ret.code = httpConnection.getResponseCode(); Log.i(TAG, "ResponseCode: "+String.valueOf(ret.code)); BufferedReader reader; if (ret.code == 200) { reader = new BufferedReader(new InputStreamReader(httpConnection.getInputStream())); } else { reader = new BufferedReader(new InputStreamReader(httpConnection.getErrorStream())); } String line; ret.body = ""; while((line = reader.readLine())!= null) { ret.body = ret.body + line; } ret.reader = new StringReader(ret.body); PsLogUtil.appendMessage(context, TAG, "Responsebody: "+ret.body); httpConnection.disconnect(); }catch (Exception e) { e.printStackTrace(); Log.e(TAG, ""+e.getMessage()); ret.body = ""; ret.code = -1; } return ret; } ==================== Thanks very much for your kindly help. Best Hugo -- 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 -- 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

