CharlesWashington
CharlesWashington

Reputation: 109

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());
        }

Upvotes: 0

Views: 165

Answers (1)

ADyson
ADyson

Reputation: 61915

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);

Upvotes: 1

Related Questions