[英]How to post a numeric value in c#
I'm trying to use HTTPclient to post to a 3rd party api and get a response. 我正在尝试使用HTTPclient发布到第三方api并获得响应。 I'm able to post to the api but the problem i'm having is that the api requires the programid to be numeric. 我可以发布到api,但是我遇到的问题是api需要programid为数字。 Whenever i try to post with this code it throws it back telling me to make the programid numeric. 每当我尝试使用此代码发布时,它都会将其扔回,告诉我将programid设为数字。
I'm at a loss as to how to send a numeric via ac#/.net post 我不知道如何通过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();
}
maybe WebClient? 也许是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);
}
just make sure you aren't passing any funny url routing characters like ? 只要确保您没有传递任何有趣的网址路由字符,例如? or & 要么 &
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.