我正在开发一个统一3d的Android应用程序,它将为用户帐户更新所述帐户以及控制应用程序后端的所有内容进行网络通信。我使用统一的WWW类将信息发送到服务器。后端是php,所有数据都存储在mysql数据库中。如何在应用程序和后端之间建立安全连接,而无需简单地获取服务器地址并将其阻止在主机文件中并提供应用程序虚假信息并与其联机。(作为示例)我&m; m没有安全专家,但我不确定我需要查看什么才能在服务器和客户端之间建立安全连接。任何帮助都会大大减少。谢谢。
答案 0 :(得分:3)
你只需要实现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");
}
}