我正在开发一个统一3d的android应用程序,它将有用于用户帐户的网络通信,更新上述帐户,以及控制应用程序后端的所有内容。我统一使用WWW类向服务器发送信息。后端是php,所有数据都存储在mysql数据库中。我怎样才能在应用程序和后端之间建立一个安全的连接,而不需要有人简单地获取服务器地址并将其阻塞在主机文件中,并输入应用程序的假信息并与其联机。(举个例子)我不是安全专家,但我也不确定为了在服务器和客户端之间建立安全连接需要查看哪些内容。任何帮助都会受到极大的伤害。谢谢。
发布于 2014-04-26 20:55:37
您只需要实现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");
}}
https://stackoverflow.com/questions/23309617
复制相似问题