如何将变量从 C# Windows 窗体应用程序传递到 PHP Web 服务
为了将变量从 C# Windows 窗体应用程序传递到 PHP Web 服务,我已经奋斗了几天.经过多次测试,我得出结论,Windows 窗体应用程序中的变量无法到达 PHP Web 服务.
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.
关于变量的一些背景知识:当用户登录到 Windows 窗体应用程序时,用户名、密码和唯一的软件令牌将发送到 Web 服务以从我的数据库进行验证.
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.
我怀疑我的问题在于我构造 URL 的方式.
I suspect my problem is in the way I structure the URL.
这是我的 C# 代码:
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());
}
您只是传递字面硬编码值username"和password",而不是变量的内容.
You're just passing the literal hard-coded values "username" and "password", not the contents of the variables.
尝试将变量连接到 URL 中:
Try concatenating the variables into the URL instead:
WebRequest request = WebRequest.Create("https://mydomain.com.au/LoginVerification.php?username=" + username + "&password=" + password + "&Token=" + Token);