简体   繁体   English

为什么相同的PHP UnityWebRequest在plesk服务器上不起作用,但在我的本地主机上起作用?

[英]Why does the same php UnityWebRequest does not work on plesk server but works on my localhost?

I am developing an app in unity and I am currently coding the login functionality. 我正在统一开发一个应用程序,目前正在编写登录功能。 I have also created a database for my users in plesk. 我还为plesk中的用户创建了一个数据库。 I have been updating and inserting new users from my apache local host normally until now. 到目前为止,我一直在正常地从apache本地主机更新和插入新用户。 I copied my php files into my hosting server and now all the responses I get are null and the response error is "Unknown error". 我将我的php文件复制到了托管服务器,现在得到的所有响应均为null,响应错误为“未知错误”。

I tried making calls directly from my browser with @_GET and they work as intended. 我尝试使用@_GET直接从浏览器中拨打电话,这些电话可以正常工作。 I also called the plesk support team, they said it should work and I could try checking the php version the server is using and match it with mine. 我还致电plesk支持团队,他们说它应该可以工作,我可以尝试检查服务器使用的php版本并将其与我的匹配。 Still nothing. 依然没有。

php code PHP代码

 if(@$_POST['cmd'] == 'login_mobile'){

    $username_input = $_POST["username"];
    $password_input = $_POST["password"];

    //to prevent mysql injections
    $username = stripcslashes($username_input);
    $password = stripcslashes($password_input);

    $query = "SELECT * FROM users WHERE first_name='$username'";
    $response = mysqli_query($dbc, $query);

    //check password
    $row = mysqli_fetch_array($response);
    if( $row['first_name'] == $username && $row['phone'] == $password ){
        $user_id = $row['id'];

        $query2 = "SELECT * FROM conversation WHERE creator_id='$user_id'";
        $response2 = mysqli_query($dbc, $query2);
        $row2 = mysqli_fetch_array($response2);

        $query_set_active = "UPDATE users SET is_active = 1 WHERE id='$user_id'";
        $response_active = mysqli_query($dbc, $query_set_active);

        echo 'Login success,' . $row['id'];
    }
    else{   
        echo 'fail';
    }   
    die;
}

unity code c# (request) 统一代码C#(请求)

IEnumerator Connection(string first_name, string password)
{
    WWWForm conn = new WWWForm();
    conn.AddField("cmd", "login_mobile");
    conn.AddField("username", first_name);
    conn.AddField("password", password);

    UnityWebRequest response = UnityWebRequest.Post("https://www.katiawashere.gr/qr/func/get_user_info.php", conn);

    yield return response.SendWebRequest();

    if (String.IsNullOrEmpty(response.error))
    {
        if (response.downloadHandler.text.Contains("Login success"))
        {
            serverResponseUi.text = "Login successfull";

            string[] splitedResponse = response.downloadHandler.text.Split(new string[] { "," }, StringSplitOptions.None);

            //Set the user id
            int.TryParse(splitedResponse[1], out StaticHolder.userid);
            SceneManager.LoadScene("Chatter");
        }
        else
        {
            serverResponseUi.text = "Could not Login";
        }
    }
    else
    {
        serverResponseUi.text = "Cannot connect to server: " + response.error;
    }
}

Here is the link that actually responds https://www.katiawashere.gr/qr/func/get_user_info.php?cmd=login_mobile&username=User&password=696969 . 这是实际上响应https://www.katiawashere.gr/qr/func/get_user_info.php?cmd=login_mobile&username=User&password=696969的链接。 The request however returns null and the request error is "Unknown error". 但是,该请求返回null,并且请求错误为“未知错误”。 I feel like searching a needle in a haystack, any feedback is appreaciated. 我感觉就像在大海捞针,任何反馈都得到了评价。

When using https you have to implement a UnityWebRequest-certificateHandler eg example from Unity 使用https您必须实现UnityWebRequest-certificateHandler,例如Unity中的示例

// Based on https://www.owasp.org/index.php/Certificate_and_Public_Key_Pinning#.Net
class AcceptAllCertificatesSignedWithASpecificKeyPublicKey : CertificateHandler
{
    // Encoded RSAPublicKey
    private static string PUB_KEY = "30818902818100C4A06B7B52F8D17DC1CCB47362" +
        "C64AB799AAE19E245A7559E9CEEC7D8AA4DF07CB0B21FDFD763C63A313A668FE9D764E" +
        "D913C51A676788DB62AF624F422C2F112C1316922AA5D37823CD9F43D1FC54513D14B2" +
        "9E36991F08A042C42EAAEEE5FE8E2CB10167174A359CEBF6FACC2C9CA933AD403137EE" +
        "2C3F4CBED9460129C72B0203010001";

    protected override bool ValidateCertificate(byte[] certificateData)
    {
        X509Certificate2 certificate = new X509Certificate2(certificateData);
        string pk = certificate.GetPublicKeyString();
        if (pk.Equals(PUB_KEY))
            return true;

        // Bad dog
        return false;
    }
}

or alternatively (unsecure to simply accept all ssl certificates) 或替代(不安全地仅接受所有ssl证书)

class AcceptAllCertificates : CertificateHandler
{
    protected override bool ValidateCertificate(byte[] certificateData)
    {
        return true;
    }
}

and use it in your request like 并在您的请求中使用它

UnityWebRequest response = UnityWebRequest.Post("https://www.katiawashere.gr/qr/func/get_user_info.php", conn);

response.certificateHandler = new AcceptAllCertificatesSignedWithASpecificKeyPublicKey();

//or
response.certificateHandler = new AcceptAllCertificates();

yield return response.SendWebRequest();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WCF Rest Web服务在localhost上运行,但在服务器上不运行 - WCF Rest Webservice works on localhost but does not work on server SQL Server连接-为什么(本地)不起作用,但是本地主机起作用 - SQL Server Connections - Why (local) doesn't work but localhost does 127.0.0.1无法正常工作,但localhost可以正常工作 - 127.0.0.1 does not work, but localhost works fine “UnityWebRequest”不包含“结果”的定义 - 'UnityWebRequest' does not contain a definition for 'result' 为什么C#DirectoryServices无法与我的LDAP服务器一起使用? - Why does C# DirectoryServices not work with my LDAP server? 为什么我的排序不起作用? - Why does my sorting not work? 为什么我的功能不起作用? - Why does my function not work? 为什么HttpRequest不能在Windows上运行但在Mac上运行? - Why does HttpRequest not work on Windows but works on Mac? 为什么 cURL 有效,但我的 HttpWebRequest 无效? - Why does cURL work, but my HttpWebRequest does not? 为什么将CollectionView绑定到Window.Visibility在将相同的绑定属性绑定到ItemsControl时不起作用? - why binding CollectionView to Window.Visibility does not work while binding to same bound property works for ItemsControl?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM