HTTP GET Request

Discussion in 'Plugin Development' started by elfin8er, Apr 30, 2013.

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

    zack6849

    by GET i assume you want to return the content on the webpage?

    Code:
        public static String get(String url) {
            string stuff;
            try {
                URL url = new URL(url);
                BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
                String str = in.readLine();
                in.close();
                if (str != null) {
                  stuff = str;
                }
            }
            catch (java.io.IOException e1) {
                stuff = e1.getMessage();
            }
            return stuff;
        }
    
     
  2. What I'm trying to do is send information to a PHP site. So for an example, if I want to send the players username for my PHP server to do stuff with I can.
     
  3. Offline

    RainoBoy97

    He means the values after the ? in the URL, so username and email.
     
  4. Ok. Say I want to send information from my plugin, to a php script I have on my web server. For an example "http://mywebsite.com/test.php?id=16". How would I do this in the most simple way possible?
     
  5. Offline

    daviga404

    The example that zack6849 gave should be sufficient, just call his get() function with the url, e.g. get("http://mywebsite.com/test.php?id=16").
     
  6. Yup, got it all figured out. Now just out of curiosity, what if I want to read the contents of a website, and constantly do so (Or at least every couple of seconds)? What would the code look like for that? Would it lag the server?
     
  7. Offline

    zack6849

    That get method will return any text the url returns.
     
  8. Offline

    herpingdo

    Run it on a new thread, or use a Bukkit scheduler.
     
  9. Do bukkit schedulers lag the server? I'm going to probably want to check the website every couple of seconds. Would that put strain on the server?
     
  10. Offline

    herpingdo

    Not that I know of... It should be just fine. If you are worried, use a thread and sleep in it.
     
  11. Awesome! Thanks!
     
Thread Status:
Not open for further replies.

Share This Page