php - Unable to connect to my web API from Java Bukkit Plugin -
i have made web api want bukkit plugin connect to. plugin sends post httpurlconnection file 'registerplugin.php' in website. code file is:
<?php require("api.php"); registerplugin($_post["name"], $_post["ip"], $_post["port"], $_post["online"], $_post["uuid"]);
?>
the code registerplugins method in file 'api.php' is:
function registerplugin($name, $ip, $port, $playersonline, $uuid) { $sql = "insert api_activeplugins (plugin_name, plugin_ip, plugin_port, players_online, plugin_uuid) values ('$name', '$ip', '$port', '$playersonline', '$uuid')"; get_mysql()->query($sql); }
and code in bukkit plugin is:
private void connect(string api, string args) { try { byte[] data = args.getbytes(charset.forname("utf-8")); int datalength = args.length(); plugin.getlogger().info(args); string request = "http://www.theperkyturkey.tk/admin/api/" + api + ".php"; url url = new url(request); httpurlconnection connection = (httpurlconnection) url.openconnection(); connection.setdoinput(true); connection.setdooutput(true); connection.setrequestmethod("post"); connection.setrequestproperty("content-type", "application/x-www-form-urlencoded"); connection.setrequestproperty("charset", "utf-8"); connection.setrequestproperty("content-length", string.valueof(datalength)); dataoutputstream out = new dataoutputstream(connection.getoutputstream()); out.write(data); out.flush(); out.close(); } catch(exception e) { e.printstacktrace(); } }
which called in onenable() method by:
string name = plugin.getdescription().getname(); string ip = plugin.getserver().getip(); string port = string.valueof(plugin.getserver().getport()); string online = string.valueof(plugin.getserver().getonlineplayers().size()); string uuid = "test"; connect("registerplugin", "name=" + name + "&ip=" + ip + "&port=" + port + "&online=" + online + "&uuid=" + uuid);
it not error database because able use method registerplugin() inside 'api.php' file without errors. error lies in connection between plugin , web api. in advance help! (by way being hosted hostinger)
Comments
Post a Comment