requsting to execute php script

Discussion in 'Spigot Plugin Development' started by 69economy, Aug 17, 2018.

  1. Hello, I'm trying to create a web administration on the server but also to control it directly from the server. (I have personal reasons and I'm learning to do so) php-> rcon script already working, but I have a problem with how to recall it and send other data.

    Currently i have this, but its not working without any error.
    Code (Text):

    public class eBan implements CommandExecutor {
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (cmd.getName().equalsIgnoreCase("eban")){
                Player player = (Player) sender;
                try {
                    player.sendMessage("Přijato");
                    URL url = new URL("http://thepixelgames.tk/scripts/ban.php");
                     URLConnection connection = url.openConnection();
                     connection.setDoOutput(true);

                     connection.setConnectTimeout(5000);
             
                       OutputStreamWriter out = new OutputStreamWriter(
                                                       connection.getOutputStream());
                       out.write("?name=" + args[0]);
                       out.flush();
                       out.close();
                       player.sendMessage("Odesláno");
                } catch (IOException e) {
                    e.printStackTrace();
                    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), e.toString() );
                    player.sendMessage("Error");
                }
            }
            return true;
        }
    }
     
     
    #1 69economy, Aug 17, 2018
    Last edited: Aug 17, 2018
  2. What you are doing is sending "?name=<some name>" in raw directly via tcp to the server, port 80, instead of including in the HTTP request.
    So do that.
     
  3. What's so hard about sending a simple http request to a website? You don't write something over a stream, but rather use a buildin class provided by the libary. If you don't know one, look for one, like this here: http://bfy.tw/JSx4