Bukkit plugin (Reading url content) help

Discussion in 'Plugin Development' started by mig4ng, Dec 29, 2013.

Thread Status:
Not open for further replies.
  1. Hello!
    I'm trying to create a bukkit plugin that reads a page and see what's the first line of it. Here's the code:
    URL url = new URL("http://myurlblablabla");
                            InputStream is = url.openStream();
                            BufferedReader br = new BufferedReader(new InputStreamReader(is));
                            String line = br.readLine();
    Not posting the url because it's a api of mine that I don't want to share for security reasons, but the url is up, then I'm reading the line with a print ou in the chat+console and it shows like this: "<html>", yet if I go on the url on my browser, it shows this:

    Hope someone can help me :S
  2. Offline


    Why not try printing out every line instead of just one?
  3. already tried that, it was giving a nullexception error somewhere :S
  4. Offline


    I'm not too familiar with reading websites, but if it's showing <html> then it's probably reading the actual source of the website rather than the content.

    Edit: yeah, just did some Googling. Looks like you'll have to parse the HTML yourself or use an external lib.
  5. how can I read for example only line 3 or 4?
  6. Offline


    This is how I check raw outputs of, like, pastebins and gists and such.
    All you have to do is recognize how the page prints out, because the lines will most likely never change.

            List<String> lines = new ArrayList<>();
                URL url = new URL("http://google.com");
                URLConnection yc = url.openConnection();
                BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
                String inputLine;
                while ((inputLine = in.readLine()) != null)
            catch (Exception e)
  7. Offline


    If you have control of the server, why are you returning HTML?

    A web "API" generally returns data, like XML or JSON or even plain text.

    I would suggest changing it if you can, it'll make life much easier on the client side when parsing.
  8. I'm not able of changing the api since it was created for other servers too, and I have no total control on it, unfortually :S
    yet I got the response from the script above, yet it does not shows either true or false :S

    Nevermind people I was using http instead of https, and the server was replying that it does not allow http.
    Thanks to all who helped.
    EDIT: How can I change the topic tittle to SOLVED?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 6, 2016
Thread Status:
Not open for further replies.

Share This Page