我在这里和整个互联网上查看了很多其他线程,我似乎无法解决这个问题..
所以基本上我已经写了这个Java代码:
public void sendReport(CommandSender sender, Player target, String reason)
{
HttpURLConnection connectionStandard = null;
String email = config.getString("rp.site.email");
String password = config.getString("rp.site.password");
String senderName = sender.getName();
String targetName = target.getDisplayName();
String reasonString = reason;
try
{
URL url = new URL("http://www.website.net/folder/connect.php");
HttpURLConnection request = (HttpURLConnection)url.openConnection();
request.setRequestProperty("Content-type","application/x-www-form-urlencoded");
request.setRequestMethod("POST");
request.setDoOutput(true);
OutputStreamWriter post = new OutputStreamWriter(request.getOutputStream());
String data = URLEncoder.encode("email", "UTF-8") + "=" + URLEncoder.encode(email.toString(), "UTF-8");
data += "&" + URLEncoder.encode("password", "UTF-8") + "=" + URLEncoder.encode(password.toString(), "UTF-8");
data += "&" + URLEncoder.encode("reporter", "UTF-8") + "=" + URLEncoder.encode(senderName, "UTF-8");
data += "&" + URLEncoder.encode("reported", "UTF-8") + "=" + URLEncoder.encode(targetName, "UTF-8");
data += "&" + URLEncoder.encode("reason", "UTF-8") + "=" + URLEncoder.encode(reasonString, "UTF-8");
post.write(data);
post.flush();
} catch (MalformedURLException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
} finally
{
if(null != connectionStandard)
{
connectionStandard.disconnect();
}
}
}
基本上,我的 php 代码看起来像这样:
<?php
require_once "db.php";
$reporter->startSecureSession();
foreach ($_POST as $post => $value) {
$post = strip_tags($post);
$value = strip_tags($value);
}
if(!(isset($_POST['email'])) or (!isset($_POST['password'])) or (!isset($_POST['reporter'])) or (!isset($_POST['reported'])) or (!isset($_POST['reason']))) {
exit("Invalid Request");
}
$password = hash("sha512", $_POST['password']);
$reporter->login(array("email" => $_POST['email'], "password" => $password), "plugin");
if($reporter->validateClient()) {
$reporter->sendReport($_POST);
header("Location: logout.php");
exit();
} else {
exit();
}
?>
当我通过 chrome 将我的详细信息发送到网页时,它可以工作并将内容发送到我的数据库,但是当我通过发送请求的命令在我的 bukkit 服务器上执行此操作时,它不会:/
谢谢您的帮助 :)