// xamarin.android c# code
void mButtonCreateContact_Click(object sender, EventArgs e)
{
WebClient client = new WebClient();
Uri uri = new Uri("http://www.mydomainname.com/abcd.php");
NameValueCollection parameters = new NameValueCollection();
parameters.Add("Name", txtName.Text);
parameters.Add("Number", txtNumber.Text);`
client.UploadValuesCompleted += client_UploadValuesCompleted;
client.UploadValuesAsync(uri, parameters);
}
这里我传递了两个参数来获取用户的输入。但是在PHP代码中它始终在isset['Name']
函数中返回false并进入else
语句
if (isset($_POST['Name']) && isset($_POST['Number']))
{
$mName = $_POST['Name'];
$mNumber = $_POST['Number'];
echo 'true';
}
else
{
echo 'false';
}
答案 0 :(得分:1)
您需要在WebClient中设置请求参数POST。
答案 1 :(得分:1)
您目前正在发送带有值的GET
,如果您想使用POST
,请将其称为:
void mButtonCreateContact_Click(object sender, EventArgs e)
{
WebClient client = new WebClient();
Uri uri = new Uri("http://www.mydomainname.com/abcd.php");
NameValueCollection parameters = new NameValueCollection();
parameters.Add("Name", txtName.Text);
parameters.Add("Number", txtNumber.Text);
client.UploadValuesCompleted += client_UploadValuesCompleted;
client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
client.UploadValuesAsync(uri, "POST", parameters);
}
答案 2 :(得分:0)
使用以POST
client.UploadValuesAsync(uri, "POST", parameters);
答案 3 :(得分:-1)
最佳方式是用户$_REQUEST
。无论你使用帖子还是获得。