[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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] query about the usage of HttpsURLConnection
Thanks for Vu-Nguyen's reply. I did more test, and here is some output about the err: = W/System.err( 1390): java.lang.NullPointerException W/System.err( 1390): at java.io.Reader.init(Reader.java:72) W/System.err( 1390): at java.io.InputStreamReader.init(InputStreamReader.java:72) W/System.err( 1390): at android.test.MyTestHttpRequest.executeHttpsPost(MyTestHttpRequest.java:262) W/System.err( 1390): at android.test.MyTestServerToolkitL.loginUser(MyTestUserServerToolkitL.java:40) W/System.err( 1390): at com.me.mytest.MyTestLoginActivity$6.run(PsLoginActivity.java:279) = It seems some null pointer is the reason? Is it? Best Hugo 2010/3/10 Trung-Liem Vo lie...@gmail.com 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:* android-developers@googlegroups.com [mailto: android-develop...@googlegroups.com] *On Behalf Of *Hugo Wang *Sent:* Wednesday, March 10, 2010 10:26 AM *To:* android-developers@googlegroups.com *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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit
[android-developers] help: HttpConnectionParams.setSoTimeout OR setConnectionTimeout NO effect??!!
Hi I am new to Android network application develop, I am trying to set the timeout with my HTTP request by using DefaultHttpClient. Sometimes I found that the TimeOut parameter has no effect, and the program will be blocking at the execute() method. Here is the outline of my code: -- HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, TIMEOUT); HttpConnectionParams.setSoTimeout(params, TIMEOUT); HttpClient httpClient = new DefaultHttpClient(params); HttpGet httpGet = new HttpGet(url); HttpResponse response; response = httpClient.execute(httpGet); ... - The platform is Android 1.6 . I wonder if the above code cannot cover some network condition where the TimeOut has no effect. Could someone give me some hint how to write a robust Timeout Code for this? Or is there any standard example? Any suggestion is appreciated. Thanks a lot in advance~ 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] help: how to compile iproute2 in android platform?
Hi I want to use the tool 'ip' to do some advanced network configuration (such as tunnel configurations and other operations) in Android/linux shell. The command 'ip' is packaged in iproute2 ( http://www.linuxfoundation.org/en/Net:Iproute2). I am new to this area. Could anyone give me some hint that how to compile this tool in Android/linux platform? btw, I saw that by default, android has built many network tools such as 'tcpdump','iptables', etc. (with the source code in external/ directory). Thanks in advance. Any comments is appreciated. 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: Porting RDP (Remote Desktop Protocol) to Android -- questions
Is there any java rdp client ? I suppose you can develop based on this? 2009/6/23 kirkbeaty kirkbe...@gmail.com Attempting to port RDP to Android ... saw someone had started this, Desktoid/Connectoid, but that effort seems to have stopped .. and I need this function immediately. I have initial screen image of the Desktop displayed (with some local Android GUI expert's help) on the Android as a Bitmap. There are several calls that RDP does which I can not find equivalents in the Android GUI. Those in the subject and others: drawGlyph, setClip, Cursor, IndexColorModel, etc. Just to get the initial image was not without considerable effort ... little things like which Bitmap.Config was used was key ... seems it requires Bitmap.Config.RGB_565 (others did not work, and without understanding as to why ?). Willing to partner with any experts out there to get this completed. Think it a very useful utility. Of course, we need to have real ENTERPRISE WPA (even iPhone has this out of the box) to really make this complete (instead of doing it on emulator only :-) Thanks for any assistance anyone can provide. Kirk Beaty kirkbe...@gmail.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---