I am coding for Android, but since it uses java based language I guess here is the right place to post. I think that this is either a bug in java or I can`t manage to do something wright.
Here is the code snippet URL url; HttpURLConnection conn = null; try { url = new URL("http://mtel.bg/sms/send_sms.php"); conn = (HttpURLConnection) url.openConnection(); }catch (MalformedURLException e1) { }catch (IOException e) { } // Set the Browser Agent conn.setInstanceFollowRedirects(false); try { Log.d("DEBUGTAG", Integer.toString( conn.getResponseCode() )); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } StringBuilder buffer = new StringBuilder(""); BufferedReader in = null; InputStreamReader deni = null; try{ Log.d("DEBUGTAG", "Lenght:" +conn.getContentLength()); deni = new InputStreamReader(conn.getInputStream()); in = new BufferedReader( deni ); String inputLine; while((inputLine = in.readLine()) != null){ buffer.append(inputLine); } deni.close(); in.close(); conn.disconnect(); }catch (Exception e) { Log.d("DEBUGTAG", "exception"); }finally{ try { if( deni != null) deni.close(); if( in != null) in.close(); } catch (IOException e) { Log.d("DEBUGTAG", "exception"); } conn.disconnect(); } Log.d("DEBUGTAG", buffer.toString()); url = null; conn = null; try { url = new URL("http://mtel.bg/sms/send_sms.php"); conn = (HttpURLConnection) url.openConnection(); }catch (MalformedURLException e1) { }catch (IOException e) { } conn.setUseCaches(true); // Set the Browser Agent conn.setInstanceFollowRedirects(true); try { Log.d("DEBUGTAG", Integer.toString( conn.getResponseCode() )); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } Log.d("DEBUGTAG", "Lenght:" +conn.getContentLength()); buffer = new StringBuilder(""); try{ //BufferedReader in; in = new BufferedReader( new InputStreamReader (conn.getInputStream()) ); String inputLine; while((inputLine = in.readLine()) != null){ buffer.append(inputLine); } conn.disconnect(); in.close(); }catch (Exception e) { } Where is the problem? I am connecting to http://mtel.bg/sms/send_sms.php with conn.setInstanceFollowRedirects(false); because I want to read some cookies and this pages redirects to another with HTTP code 302, but since setInstanceFollowRedirects is false, there is no redirection and the page is blank. The ContentLength is 0, but I am trying to read the page. I get no error here in = new BufferedReader( new InputStreamReader(conn.getInputStream()) ); . Until now everything is ok. But here comes the problem. After I try to read the page again with conn.setInstanceFollowRedirects(true); , I get ContentLenght -1 and no output. The strange thing is that if I call System.gc(); before opening the second page, there is no problem, but I don`t want to call System.gc (); Could you please tell me where the problem is? I am trying different things to debug, but nothing :( I posted the topic first at sun`s java forums - http://forums.sun.com/thread.jspa?threadID=5415660&tstart=0 Thanks! -- 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