[英]C# application receives data from php
I wanna receive The Received Successfully message from php but instead i receive the page source!我想收到来自 php 的成功接收消息,但我收到了页面源!
C# Code C# 代码
using (WebClient wc = new WebClient())
{
NameValueCollection students = new NameValueCollection();
{
students.Add("sID", "6");
students.Add("sName", "anas");
students.Add("sMajor", "prog");
String response = Encoding.UTF8.GetString(wc.UploadValues(url, students));
students.Clear();
}
}
PHP Code PHP代码
if(isset($_POST['sID']) && isset($_POST['sName']) && isset($_POST['sMajor']))
{
echo "Received Successfully";
$stID = $_POST['sID'];
$stName = $_POST['sName'];
$stMajor = $_POST['sMajor'];
$insertQuery = "insert into myTable (ID,stName,stMajor) values ('".$stID."','".$stName."','".$stMajor."')";
$InsertQ = mysqli_query($Connection, $insertQuery);
}
Please try below code after replacing your URL请在替换您的 URL 后尝试以下代码
public static string GetResponseFromServer()
{
using (var client = new HttpClient())
{
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("sID", "6"),
new KeyValuePair<string, string>("sName", "anas"),
new KeyValuePair<string, string>("sMajor", "prog"),
});
var result = client.PostAsync("Your URL Goes here", content);
string resultContent = result.Result.Content.ReadAsStringAsync().Result;
return resultContent;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.