我试图通过多种方式解决我的问题,但没有成功,除了切换到DownloadString和发送一个GET方法,这是我不想做的。
因此,我只是试图使用WebClient.UploadString方法将一个字符串变量上传到一个简单的PHP脚本中,但由于忽略的原因,PHP脚本无法接收该脚本。
下面是我上传字符串变量的C#代码
WebClient wc = new WebClient();
string username = "John";
wc.UploadString("http://127.0.0.1/index/username.php", username);下面是将C#变量存储在$username var中的PHP代码,然后存储在数据库中
$username = $_POST['username'];
if(isset($username) && $username != '')
{
$sqlqueries;
}发布于 2022-09-25 17:25:16
要解决这个问题,我们只需使用System.Collections.Specialized.NameValueCollection将UploadString方法转换为UploadValues
C#代码应该如下所示:
var data = new System.Collections.Specialized.NameValueCollection { ["name"] = "John"};
WebClient wc = new WebClient();
wc.UploadValues("http://127.0.0.1/index/username.php", data);PHP代码看起来仍然是一样的:
$username = $_POST['username'];
if(isset($username) && $username != '')
{
$sqlqueries;
}https://stackoverflow.com/questions/73841117
复制相似问题