简体   繁体   English

如何将变量从C#Windows窗体应用程序传递到PHP Web服务

[英]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. 我一直在努力将变量从C#Windows窗体应用程序传递到PHP Web服务。 After numerous tests I concluded that the variables from the Windows Form Application does not reach the PHP Web-Service. 经过大量测试后,我得出结论,Windows窗体应用程序中的变量未到达PHP Web服务。

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. 有关变量的背景知识:当用户登录Windows窗体应用程序时,用户名,密码和唯一软件令牌将发送到Web服务,以从我的数据库进行验证。

I suspect my problem is in the way I structure the URL. 我怀疑我的问题出在构建URL的方式上。

Here is my C# Code: 这是我的C#代码:

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: 尝试将变量串联到URL中:

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

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

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