【问题标题】:How can I pass a string as parameter? using System.Net.Http;如何将字符串作为参数传递?使用 System.Net.Http;
【发布时间】:2017-08-05 09:24:55
【问题描述】:

我正在使用这条线

client.PostAsync("mysite.net/login.asmx/login", content);

我需要我的内容类似于 id=21&name=myname&password=pass&json=1 它应该是一个字符串 但这里接受的类型是 FormUrlEncodedContent ,因此我不知道这个类是如何创建值的,它是否像 json 一样工作以及它是否会改变这个结构 id =21&name=myname&password=pass&json=1 我需要的(应该是网址的其余部分) 例如,如何发送和接收将其转换为我的类用户的响应?

我也在用它

var content = new FormUrlEncodedContent(new[]
                    {
                        new KeyValuePair<string, string>("id", "125"),
                        new KeyValuePair<string, string>("mailadress", login),
                        new KeyValuePair<string, string>("password", pass),
                        new KeyValuePair<string, string>("json", "1"),
                     });

我的网络服务将如何接收它?这个类(上)如何组织键值?​​

我的班级

class User
{
    public string codigo { get; set; }
    public string nome { get; set; }
    public string email { get; set; }
    public string senha { get; set; }
    public string imagem { get; set; }
    public DateTime dataDeNasc { get; set;}
    public string cidade { get; set; }
    public string estado { get; set; }
    public string telefone { get; set; }
    public string sexo { get; set; }
}

非常感谢。 我真的需要这个帮助

【问题讨论】:

  • receive the response converting it to my class user 请附上用户的源代码。
  • 我会的,等等……
  • @mjwills 我该怎么办??你能帮忙吗?

标签: c# visual-studio post system.net.httpwebrequest


【解决方案1】:

正文的发送将与表单 URL 编码中的完全一样(类似于您的示例字符串),在您的 C# 示例中它将被发送为:

id=125&mailaddress=login&password=pass&json=1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-02
    • 1970-01-01
    相关资源
    最近更新 更多