0

I'm trying reading to read a webpage. In a browser it just looks like this:

<b>Failure</b>
<b>Success</b>

But When I read it with my application it gives me this: http://pastebin.com/vJ6GDWpx

This is my code:

URL url = new URL("http://example.com/auth.php?username=" + username + "&password=" + password);
URLConnection urlconnection = url.openConnection();
urlconnection.setConnectTimeout(10000);
urlconnection.setReadTimeout(10000);
urlconnection.addRequestProperty("Host", "example.com");
urlconnection.addRequestProperty("Connection", "keep-alive");
urlconnection.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20120716 Firefox/15.0a2");
urlconnection.addRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
urlconnection.addRequestProperty("Accept-Language", "en-US,en;q=0.8");
urlconnection.addRequestProperty("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.3");

BufferedReader br = new BufferedReader(new InputStreamReader(urlconnection.getInputStream()));
String result;
while ((result = br.readLine()) != null) {
    System.out.println(result);
}
br.close();

How can I solve this problem?

Works with HTMLUnit but their library is sooo big. Is there a smaller solution?

user2997204
  • 1,171
  • 1
  • 10
  • 21
  • 2
    `This website requires javascript/cookies support in order to operate properly.` so manually navigate to page after desable javascript and cookies in your browser..you will not see page correctly .you have to use a library like htmlunit – Madhawa Priyashantha Dec 25 '14 at 02:19
  • It means that there is more to that webpage than meets the eye. Could you disable JavaScript in your request? – Makoto Dec 25 '14 at 02:23
  • @FastSnail still working without javascript, but won't work without cookies. Giving the error in chrome. – user2997204 Dec 25 '14 at 02:29
  • @user2997204 i'm not sure but read[Send cookie with HTTP request] this http://stackoverflow.com/a/2793153/2227526. – Madhawa Priyashantha Dec 25 '14 at 02:38

0 Answers0