Bukkit plugin (Reading url content) help

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

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

    mig4ng

    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:
    Code:
    URL url = new URL("http://myurlblablabla");
                            InputStream is = url.openStream();
                            BufferedReader br = new BufferedReader(new InputStreamReader(is));
     
                            String line = br.readLine();
     
                            br.close();
                            is.close();
    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:
    [​IMG]

    Hope someone can help me :S
     
  2. Offline

    adam753

    Why not try printing out every line instead of just one?
     
  3. Offline

    mig4ng

    already tried that, it was giving a nullexception error somewhere :S
     
  4. Offline

    Ronbo

    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.
    mig4ng

    Edit: yeah, just did some Googling. Looks like you'll have to parse the HTML yourself or use an external lib.
     
  5. Offline

    mig4ng

    how can I read for example only line 3 or 4?
     
  6. Offline

    ZeusAllMighty11 Retired Staff

    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.

    Code:
            List<String> lines = new ArrayList<>();
            try
            {
                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)
                {
                    lines.add(inputLine);
                }
                in.close();
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
    
     
  7. Offline

    NathanWolf

    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. Offline

    mig4ng

    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
    [​IMG]

    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