我在API 1中有一个如下所示的端点
[HttpPost]
public ActionResult PostSchoolQuery([FromBody] SchoolQueryModel schoolQueryModel, [FromHeader] string authorization)
{
}
这里的请求模型类如下所示
public class SchoolQueryModel
{
public List<Guid?> SchoolIds { get; set; }
public List<Guid?> DistrictIds { get; set; }
}
当我尝试从API 2调用端点PostSchoolQuery时,如下所示,在api-1中,我总是收到空值
public ActionResult GetUserSchools(SchoolQueryModel getSchoolsModel)
{
dynamic schoolDetails = null;
var requestContent = new JsonSerializer.Serialize(getSchoolsModel);
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Authorization", _infrastructureAuthKey);
var responseTask = client.PostAsync("http://localhost:6200/api/post_school_query", requestContent);
if (responseTask.Result.IsSuccessStatusCode)
{
var readTask = responseTask.Result.Content.ReadAsAsync<JObject>();
readTask.Wait();
schoolDetails = readTask.Result;
}
}
}
请告诉我一声,谢谢
2条答案
按热度按时间2izufjch1#
试试这个
PostAsJsonAsync
cgfeq70w2#
这一条对我很有效,我还介绍了一些更好的做法:
async/await
的功能。你不应该直接使用.Result
。HttpClient
per request.