Hello forum!
I would like to ask what's wrong with my code since I haven't found any solution yet. Currently it looks like this: (it's not my own code, I found it somewhere and changed it but don't remember the source anymore)
try { String url = mywebsite here; URL obj = new URL(url); HttpURLConnection conn = (HttpURLConnection) obj.openConnection(); conn.setReadTimeout(5000); conn.addRequestProperty("Accept-Language", "en-US,en;q=0.8"); conn.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:20.0) Gecko/20100101 Firefox/20.0"); conn.addRequestProperty("Referer", "google.com"); BufferedReader in = new BufferedReader( new InputStreamReader(conn.getInputStream())); String inputLine; StringBuffer html = new StringBuffer(); while ((inputLine = in.readLine()) != null) { html.append(inputLine); } in.close(); } catch (Exception e) { e.printStackTrace(); }
It actually works, but not 100%. Problems:
1. It seems like my application hangs itself while downloading the page. Is there any way to fix that?
2. I attached a picture of how the response looks. ALTHOUGH in the log.txt it says the right response without those weird "drawings" before the "hello" reponse.
Thanks a lot in advance, I hope my problem is understandable and please keep in mind that I just started with Java a few days ago :)