java - HttpConnection - javax.microedition, returning -1 for getLength() method -
i trying program simple mobile application (j2me) in java. idea access website via url input , read contents of website buffer.
here's problem. works fine url's not others? example below (wikipedia) works fine. take "http://java.com/en/about/" example , "httpconnection hc" returns -1 getlenght() there no content read buffer?
here's code:
string url = "http://en.wikipedia.org/wiki/rss"; //sets httpconnection , inputstream using url variable httpconnection hc = null; inputstream = null; try { hc = (httpconnection) connector.open(url); = hc.openinputstream(); } catch (ioexception ie) { system.out.println(ie.getmessage()); } //reader object created read input inputstream reader rdr = new inputstreamreader(is); //variable "content" store html code string content = ""; //get lenght of data set buffer sizes int len = (int) hc.getlength();
any ideas? let me know if i've missed out!
just info using netbeans 6.9.1
library httpconnection "javax.microedition.io.httpconnection;" + "import javax.microedition.io.connector;"
the http response java.com is
http/1.1 200 ok server: sun-java-system-web-server/7.0 date: wed, 23 feb 2011 11:07:44 gmt content-type: text/html;charset=utf-8 set-cookie: jsessionid=b62f3dfb233bb2806018ec721f6c3fd7; path=/ content-encoding: gzip vary: accept-encoding transfer-encoding: chunked
the http response wikipedia is
http/1.0 200 ok date: wed, 23 feb 2011 10:18:56 gmt server: apache cache-control: private, s-maxage=0, max-age=0, must-revalidate content-language: en vary: accept-encoding,cookie last-modified: fri, 18 feb 2011 00:23:59 gmt content-encoding: gzip content-length: 24905 content-type: text/html; charset=utf-8 age: 2984 x-cache: hit sq61.wikimedia.org, miss sq38.wikimedia.org x-cache-lookup: hit sq61.wikimedia.org:3128, miss sq38.wikimedia.org:80 connection: keep-alive
as see, http response of http://java.com/en/about/ doesn't contain content-length header, content chunked.
so, getlength() return -1.
Comments
Post a Comment