【发布时间】:2021-02-14 14:28:19
【问题描述】:
我正在尝试获取 bin 为“0001”的数据
string bin = "0001"
HttpClient client = new HttpClient();
string uri = $"https://localhost:44316/api/Bplo?bin={bin}";
HttpResponseMessage response = await client.GetAsync(uri);
if (response.IsSuccessStatusCode)
{
var result = await response.Content.ReadAsAsync<BploModel>();
return result;
}
else
{
throw new Exception(response.ReasonPhrase);
}
尝试将其添加到列表中,但仍返回 null。
【问题讨论】:
-
你需要证明你的有效载荷是你认为的那样。使用 Fiddler,或者改为获取字符串
-
这是一个 HTTP 响应。您确定响应包含 BploModel 对象而不是字节数组或 s 字符串吗?看起来内容无法转换为遗传参数类型。也许您应该尝试使用像 ReadAsStringAsync 这样的原始 HttpContent 方法。您需要手动反序列化任何字节数据。像类这样的数据类型是语言细节。 HTTP 规范不支持特定语言的日期类型。
-
正如@thegeneral 所说,使用 Fiddler。但是,由于您所做的只是 GET,因此只需在浏览器中进行测试以查看服务器返回的内容
-
@BionicCode 你说得对,我的有效载荷不匹配。在我将字节数据转换为对象后,代码工作。非常感谢!!让我免于再进行 4 小时的调试,如何标记您的答案?
标签: c# wpf mvvm get caliburn.micro