c# - 使用 SQL 的 Unity 3D 安全身份验证

标签 c# php android mysql unity-game-engine

我正在 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");
}

关于c# - 使用 SQL 的 Unity 3D 安全身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23309617/

相关文章:

c# - Type Class(在 app_Code 中)存在于 "solution.dll"和 "app_code.wxdafd.dll"中

c# - SmtpClient 在发送时从服务器获取结果

c# - WPF:ComboBox F4 键未在 KeyDown 事件中触发

php - 为什么在 PHP 函数名中使用双下划线 (__)?

php - 如何在SQL数据库中显示二进制形式的图像?

php - 如何让PHP和IOS Iphone加密通话?

c# - 如何获取成员(member)的全名

java - 用于自定义 View 的 Android onTouchEvent

Android微调器提示文本不显示

java - 如何从 fragment 中的另一个布局访问按钮