Unity3d POST而不是GET更改

时间:2014-04-16 07:58:47

标签: c# mysql post

我已经制作了这个发送到数据库的简单登录系统。但我的问题是它使用GET方法,我希望它使用POST方法,但我不知道如何做到这一点,让它改变。

你知道吗?

    using UnityEngine;
    using System.Collections;

    public class LoginMenu : MonoBehaviour
    {
  //url of the login script, wich is server side.
string loginURL = "http://127.0.0.1/login.php";
//creation of the strings we use to log in.
string userName = "";
string passWord = "";
string problem = "";
//creating the int's for the height and width of the screen.
int rectWidth = 430;
int rectHeight = 240;
//create the int to check if ppl spam the login button.
int passTries = 0;

//makes the big box for our menu.
void OnGUI()
{
GUI.Window (0, new Rect((Screen.width - rectWidth) / 2, (Screen.height - rectHeight) / 2, rectWidth, rectHeight), LoginWindow, "Login");
}

//creates al the text fields and puts the in the right position.
void LoginWindow(int windowID)
{
    GUI.Label (new Rect(170, 40, 130, 100), "----Username----");
    userName = GUI.TextField(new Rect(30, 60, 375, 30), userName);
    GUI.Label (new Rect(170, 92, 130, 100), "----Password----");
    passWord = GUI.PasswordField(new Rect(30, 115, 375, 30), passWord, "*"[0], 25);

    //creates a login button and  executes code when clicked
    if (GUI.Button (new Rect(25, 160, 175, 50), "Login"))
    {
        if (passTries >= 3)
        {
            problem = "Maximum tries of 3 reached, please wait 10 min";
            StartCoroutine(MaximumTries());
        }
        else
        {
            StartCoroutine(handleLogin(userName, passWord));
        }
    }
    //makes a register button and loads the register menu if clicked.
    if (GUI.Button (new Rect (225, 160, 175, 50), "Register"))
    {
        Application.LoadLevel ("Register");
    }
    //this displays the error if there is one.
    GUI.Label(new Rect(120, 210, 300, 100), problem);

}
//this send the info that is filled in to the login file on the server.
IEnumerator handleLogin(string userNamez, string passWordz)
{
    problem = "Checking username and password....";
    string login_URL = loginURL + "?username=" + userNamez + "&password=" + passWordz;
    WWW loginReader = new WWW (login_URL);
    yield return loginReader;

    if (loginReader.error != null)
    {
        problem = "Could not locate page";
    }
    else
    {

        if (loginReader.text == "right")
        {
            problem = "logged in";
        }
        else
        {
            problem = " invalid user/pass";
            passTries += 1;
        }
    }

}


//this disables the login if people have spammed the login button with the wrong password for more than 3 tries
IEnumerator MaximumTries()
{
    yield return new WaitForSeconds(1);// set to 600 when putting in the game
    passTries = 0;

}

}

0 个答案:

没有答案