Get website content

Discussion in 'Plugin Development' started by mike2033, May 1, 2013.

Thread Status:
Not open for further replies.
  1. Offline


    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.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", "");
                        BufferedReader in = new BufferedReader(
                                                  new InputStreamReader(conn.getInputStream()));
                        String inputLine;
                        StringBuffer html = new StringBuffer();
                        while ((inputLine = in.readLine()) != null) {
                        } catch (Exception e)
    It actually works, but not 100%. Problems:

    1. It seems like the server hangs itself while downloading the page. Is there any way to fix that?
    2. It somehow looks wrong. ALTHOUGH in the serverlog.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 :)
  2. Offline


    Hi mike,
    I dont know what your second problem is or how to fix it, but i would use a new thread to load the website.
    Here is you can see how to use threads in bukkit.
  3. Offline


    Hello again! I wanted to ask if you can help me including my source under a thread. I don't understand how it works in Java.

    Thanks in advance
Thread Status:
Not open for further replies.

Share This Page