因此,我了解GetAsync的工作原理,并且服务器上具有可以与我要完成的工作一起工作的脚本。但是就将数据获取到服务器而不是从json读取数据而言,我该怎么做?在服务器端,我的PHP脚本从提交的JSON获取所有发布数据,并检查包含所有信息的数据库,如果不存在,则将其插入。 (这是一个禁令系统。但是我不确定我是否正确设置了roblox端,或者我是否正确设置了服务器端。这是我的代码:
这正在Custom Adonis管理系统中运行
SendWebBan = function(plr,UserID,Username,Agent,Comment)
local http = game:GetService("HttpService")
local Reason = "Banned in game by AAC Admin."
local url = "URL HERE/gamebanlistener.php"
local data = {
["UserID"] = UserID,
["Username"] = Username,
["Agent"] = Agent,
["Reason"] = Reason,
["Comment"] = Comment
}
local encode = http:JSONEncode(data)
local reponse,err = pcall(function()
http:PostAsync(url,encode)
end)
print(reponse)
if reponse == "false" then
Remote.MakeGui(plr,"Notification",{
Title = "Failed";
Message = "Ban Failed";
Duration = 10;
})
elseif reponse == "true" then
Remote.MakeGui(plr,"Notification",{
Title = "Success";
Message = "Ban Successful";
Duration = 10;
})
else
Remote.MakeGui(plr,"Notification",{
Title = "Failed";
Message = "Ban Failed";
Duration = 10;
})
end
end;
<?php
$ServerKey = "key here";
$APIKey = $_POST["key"];
$Data = json_decode($_POST['data']);
$UserID = $Data.UserID;
$Username = $Data.Username;
$Agent = $Data.Agent;
$Reason = $Data.Reason;
$Comment = $Data.Comment;
$Date = date("d/m/Y");
if($APIKey == $ServerKey){
//$conn = mysqli_connect($host,$dbuser,$dbpassword,$db);
$Connection = mysqli_connect(sql credentials here);
if($Connection->connect_errno)
{
echo('{"Status":"'. $Connection->connect_errno . '"}');
}else {
$BlacklResult = $Connection->query("SELECT * FROM bans"); //Blacklist is the name of my Bans database
if($BlacklResult->num_rows > 0)
{
while($Row = $BlacklResult->fetch_assoc()){
if($Row != null){
if($Row["UserID"] == $UserID){
echo 'Status:false';
return;
}else{
$Connection->query("INSERT INTO bans(UserID, Username, Agent, BanReason, BanComment,DateOfBan) VALUES(".$UserID.",".$Username.",".$Agent.",".$Reason.",".$Comment.",".$Date.");");
echo 'Status:true';
}
};
};
};
};
}else {
echo('{"Status":"API KEY"}');
};
?>
当您调用一个函数时,返回的元组是一个布尔值,后跟该函数的结果。如果函数抛出错误,则结果将替换为错误字符串。尝试进行此更改: