I am using a Http Get to request a website with a total of 7 Html Inputs on it.
However, when I get the page and output it, only 5 inputs appear (in either my console or outputted to a text file).
The website I'm trying to get the 7 inputs for is an intranet site so it'd be of no use to provide the address.
This is my code/ "http getting" method
//GET a web page and store as string in "htmlpage"
DefaultHttpClient httpclient = new DefaultHttpClient();
//Sometimes I need the below code, but not this time
//httpclient.setRedirectStrategy(new RedirectStrategy());
HttpGet httget = new HttpGet("example-website.aspx");
HttpResponse response = httpclient.execute(httget);
HttpEntity entity = response.getEntity();
InputStream in = entity.getContent();
StringBuffer charBuf = new StringBuffer();
do{char c = (char)in.read();
charBuf.append(c);
}while (charBuf.length() < entity.getContentLength());
String htmlpage = charBuf.toString();
charBuf.delete(0, charBuf.length()-1);
in.close();
EntityUtils.consume(entity);
httget.abort();
FileOutputStream fo = new FileOutputStream("please_have_7_this_time.html");
fo.write(htmlpage.getBytes());
fo.flush();
fo.close();
entity.getContentLength()
is returning an incorrect value? what if you loop on your input untilin.read()
returns -1? – dldnh Mar 15 '12 at 16:10