首页 > 解决方案 > 托管在 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。

标签: asp.netazureasp.net-web-api

解决方案


所以这是解决方案。我仍然不知道为什么当 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 上无效仍然是一个谜。


推荐阅读