Well, my guess would be the long time can be attributed to the while loop you have. That is probably where your code is getting stuck.
HttpResponse response = client.execute(request); Try putting the log after this line, and see the times. If its still quite a lot, then you have to worry. Kumar Bibek http://techdroid.kbeanie.com http://www.kbeanie.com On Fri, Nov 19, 2010 at 4:30 AM, Wipeout <[email protected]> wrote: > Hey guys, > This is my first post to the Android Developers group. I have been > working with HTTP communication in the Android SDK and have noticed > that calls to a web service through my app are very slow (taking > 800+ms on high speed wifi). They take less than 100ms if I call the > web service through the phone's browser. I am developing on a Google > Nexus One. The size of the data returned is very small, <1K. I have > tried enabling gzip compression, and that helps slightly but I assume > there is another problem at hand. I have tried using SOAP with the > ksoap2-android library, as well as making things simple using > HttpClient and InputStreamReader. Below is my code for the fastest I > can make the app perform; using no SOAP, and using GZIP compression. I > apologize for the lengthy code -- I think all of it is beneficial for > determining the best way to make this request and response happen > faster. > > [code] > public String GetRest() > { > > long startTime = System.currentTimeMillis(); > String result = ""; > > Log.v("time", "Beginning rest: " + (System.currentTimeMillis() - > startTime) + "ms"); > > try > { > HttpClient client = new DefaultHttpClient(); > HttpGet request = new HttpGet("https://usad.enlyght.com/ws/ > AndroidService.asmx/GetWebServiceVersion"); > request.addHeader("Accept-Encoding", "gzip"); > > Log.v("time", "Before call: " + (System.currentTimeMillis() > - > startTime) + "ms"); > HttpResponse response = client.execute(request); > InputStream instream = response.getEntity().getContent(); > Header contentEncoding = response.getFirstHeader("Content- > Encoding"); > if (contentEncoding != null && > contentEncoding.getValue().equalsIgnoreCase("gzip")) { > instream = new GZIPInputStream(instream); > } > InputStreamReader isreader = new > InputStreamReader(instream); > BufferedReader reader = new BufferedReader(isreader); > StringWriter sw = new StringWriter(); > > String read; > while ((read = reader.readLine()) != null) { > result += read; > } > > client.getConnectionManager().shutdown(); > } > catch (Exception e) {} > Log.v("time", "End rest: " + (System.currentTimeMillis() - > startTime) + "ms"); > > return result; > } > [/code] > > Regards, > Adam Smith > Norsoft > > -- > 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

