求C#的UWP应用POST得到数据的示例,封装一个方法就好。请用Windows.Web.Http System.Net.Http来写
答案:1 悬赏:80 手机版
解决时间 2021-11-20 06:34
- 提问者网友:遮云壑
- 2021-11-20 02:56
求C#的UWP应用POST得到数据的示例,封装一个方法就好。请用Windows.Web.Http System.Net.Http来写
最佳答案
- 五星知识达人网友:纵马山川剑自提
- 2021-11-20 04:35
using System.Net.Http;
using (var client = new HttpClient())
{
var content = new FormUrlEncodedContent(new Dictionary()
{
{ "Sel_XNXQ", "20160" },
{ "Sel_KC", "065954" },
{ "gs", "1" },
{ "txt_yzm", "M984" }
});
var response = await client.PostAsync("地址", content);
if (response.IsSuccessStatusCode)
{
string responseBody = await response.Content.ReadAsStringAsync(); // 返回结果
}
}
徒手写的代码,可能有拼写错误。
追问The character set provided in ContentType is invalid. Cannot read content as string using an invalid character set异步调用的时候出现这个错误是哪里错了?追答编码字符集的问题,执行到哪一步出错的?
using (var client = new HttpClient())
{
var content = new FormUrlEncodedContent(new Dictionary
{
{ "Sel_XNXQ", "20160" },
{ "Sel_KC", "065954" },
{ "gs", "1" },
{ "txt_yzm", "M984" }
});
var response = await client.PostAsync("地址", content);
if (response.IsSuccessStatusCode)
{
string responseBody = await response.Content.ReadAsStringAsync(); // 返回结果
}
}
徒手写的代码,可能有拼写错误。
追问The character set provided in ContentType is invalid. Cannot read content as string using an invalid character set异步调用的时候出现这个错误是哪里错了?追答编码字符集的问题,执行到哪一步出错的?
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯