繁体   English   中英

如何在C#中发布数值

[英]How to post a numeric value in c#

我正在尝试使用HTTPclient发布到第三方api并获得响应。 我可以发布到api,但是我遇到的问题是api需要programid为数字。 每当我尝试使用此代码发布时,它都会将其扔回,告诉我将programid设为数字。

我不知道如何通过ac#/。net发送数字

using (var client = new HttpClient())
{
    var values = new Dictionary<string, string>
    {
       { "accesstoken", authtoken },
       { "programid", programid},
       { "email", person.Email },
       { "thirdparty1", person.ID.ToString() }
    };

    var content = new FormUrlEncodedContent(values);
    var response = client.PostAsync("url", content);
    var responseString = response.Result.Content.ReadAsStringAsync();
}

也许是WebClient?

using (var client = new WebClient())
            {
                var values = new Dictionary<string, string>
    {
       { "accesstoken", authtoken },
       { "programid", programid.ToString()},
       { "email", person.Email },
       { "thirdparty1", person.ID.ToString() }
    };

                var param = string.Join("&", values.Select(x => x.Key + "=" + x.Value).ToArray());

                client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
                string HtmlResult = client.UploadString(URI, "POST", param);
            }

只要确保您没有传递任何有趣的网址路由字符,例如? 要么 &

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM