简体   繁体   中英

How to pass variables from C# Windows Form Application to PHP Web-Service

I have been battling a few days to pass variables from C# Windows Form Application to a PHP Web-Service. After numerous tests I concluded that the variables from the Windows Form Application does not reach the PHP Web-Service.

It seems like my method of passing variable is not correct.

A bit of background on the variables: When the user login to the Windows Form Application, the username, password and a unique software token is send to the Web-Service for validation from my database.

I suspect my problem is in the way I structure the URL.

Here is my C# Code:

var Token = "Token Number";
var username = txtusername.Text;
var password = txtpassword.Text;

        try
        {
            WebRequest request = WebRequest.Create("https://mydomain.com.au/LoginVerification.php?username=username&password=password&Token=Token");
            request.Method = "GET";
            WebResponse response = request.GetResponse();
            Stream dataStream = response.GetResponseStream();
            // Open the stream using a StreamReader for easy access.  
            StreamReader reader = new StreamReader(dataStream);
            // Read the content.  
            var responseFromServer = reader.ReadToEnd();
            MessageBox.Show(responseFromServer.ToString());
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }

You're just passing the literal hard-coded values "username" and "password", not the contents of the variables.

Try concatenating the variables into the URL instead:

WebRequest request = WebRequest.Create("https://mydomain.com.au/LoginVerification.php?username=" + username + "&password=" + password + "&Token=" + Token);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM