asp.net - 托管在 azure 上的 webapi 总是收到一个空列表
问题描述
所以这里是场景。我将 14 个对象的列表发送到托管在 azure 上的 webapi。但它总是收到一个空列表。我像这样从后端调用 webapi。
using (HttpClient objHttpCLient = new HttpClient())
{
HttpResponseMessage objMessage = objHttpCLient.PostAsync(new Uri(strUrl), new StringContent(JOContent.ToString(), Encoding.UTF8, "application/JSON")).Result;
var ResponseClientConfiguration = objMessage.Content.ReadAsStringAsync();
sw.WriteLine(objMessage.StatusCode.ToString());
if (objMessage.IsSuccessStatusCode)
{
sw.WriteLine(ResponseClientConfiguration.Result);
objResponse = JObject.Parse(ResponseClientConfiguration.Result);
strConfigurationJSON += objResponse["ConfigurationJson"].ToString();
}
}
现在,当 webapi 在我的本地环境中运行时,这可以完美地工作。它接收所有 144 个对象,但一旦它托管在 azure 上,它总是会收到一个空的 lit。
解决方案
所以这是解决方案。我仍然不知道为什么当 webApi 项目托管在 azure 上时上述方法不起作用,但在本地托管或普通网络服务器上时起作用。解决方法是创建一个类来覆盖对象列表,即对象列表现在将成为此类的属性。
在webApi上我期望的参数之前如下
public JObject Validate(List<DateTime> lstDates)
在它之后
public JObject Validate(DateLst objDates)
其中 DateLst 类结构如下
public class DateLst
{
public List<DateTime> lstDates{ get; set;}
}
现在为什么这有效而前者在 azure 上无效仍然是一个谜。
推荐阅读
- mysql - Mysql - 检查日期是否在某个范围内
- python - 读取带有中文字符的 CSV 文件时出现 UnicodeDecodeError
- python - 如何使用 Python 从定义的 HTML Javascript 块中解析 JSON 数据集?
- python - TensorFlow 优化器是否最小化 API 实现的小批量?
- google-sheets - Conditionally summing the contents of one column based on another ... in one formula
- optimization - 文件名匹配与文件名匹配之间的性能比较。分区修剪
- c++ - WM_CTLCOLORSTATIC 永远不会在 WIN32 应用程序中触发
- android - 如何使用图像箭头自定义微调器
- c++ - 添加静态 constexpr 成员是否会更改结构/类的内存映射?
- java - 无法比较字符串