我正在unity 3d中开发一个android应用程序,该应用程序将为用户帐户提供网络通信,更新所述帐户,并控制应用程序后端的一切。我使用统一的WWW类向服务器发送信息。后端是php,所有数据都存储在mysql数据库中。我如何在应用程序和后端之间建立安全连接,而不需要有人简单地获取服务器地址并将其屏蔽在主机文件中,并向应用程序提供虚假信息并使用它联机。(例如)我不是安全专家,但我不确定为了在服务器和客户端之间创建安全连接,我还需要查找什么。任何帮助都将不胜感激。非常感谢。
您只需要实现www类
void start()
{
StartCoroutine(retrieveHighscores()); //Start out by getting the current scores.
}
IEnumerator retrieveHighscores()
{
var form = new WWWForm(); // create a new form
form.AddField("Nipun",name); // add the data you want to retrieve in the form fields
var rawData = form.data;
var headers = form.headers; // here headers will be used to authenticate the credentials of the person trying to access
headers["Authorization"]="Basic " + System.Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes("username:password"));
WWW webRequest = new WWW("https://abc.com/test.php", rawData, headers); //
yield return webRequest;
if (webRequest != null) {
//here you have successfully got the response back from the server , here i am adding the whole response in a string and then splitting the string based on the format of the data i received.
string x = webRequest.text;
string[] lines = webRequest.text.Split(new string[] { System.Environment.NewLine }, System.StringSplitOptions.RemoveEmptyEntries); //Split the response by newlines.
Debug.Log(x); // to check what you received
scores = new Dictionary<string, int>(); //Always reset our scores, as we just got new ones.
foreach (string line in lines) //Parse every line
{
// code here how you want to use the split up data you received
}
}
else
Debug.Log("error");
}
}