我正在尝试将此 JSON 数据字符串发布到我的 php 站点:
{
"tag":"login"
"email":"email@email.com"
"password":"P@ssw0rd"
}
这是我拥有的 C# 代码:
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://localhost/login/");
string link = "http://localhost/login/";
UserCredentials cred = new UserCredentials(email.Text, pass.Password.ToString());
var data = new Dictionary<string, List<UserCredentials>>();
string json = JsonConvert.SerializeObject(data, Formatting.Indented);
HttpResponseMessage re = await client.PostAsync(link, new StringContent(json));
用户凭证类:
public class UserCredentials
{
public UserCredentials(string user, string pass)
{
User = user;
Pass = pass;
Tag = "login";
}
internal string User;
internal string Pass;
internal string Tag;
}
在我的 php 脚本中:
<?php
if (isset($_POST['tag']) && $_POST['tag'] != '') {
echo "got tags";
else
echo "didn't get anything";
?>
有谁知道我应该如何通过 postasync 方法发送标签?我得到'没有得到任何东西'..请帮助