在Azure Web App中的nuget更新之后,Web API返回HttpResponseMessage对象 [英] Web API returning HttpResponseMessage object after nuget updates in Azure Web App
问题描述
我使用的是Web API 5,它运行良好,我返回了一个Content = new StringContent("content here")
的HttpResponseMessage对象,并在调用该API时获得了预期的内容.
I'm using Web API 5, it's has been working fine, I return a HttpResponseMessage object with Content = new StringContent("content here")
and get the expected content when calling the API.
[HttpPost]
public async Task<HttpResponseMessage> GetData([FromBody]DataObject input)
{
.....
return new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(JsonConvert.SerializeObject(returnModel))
};
}
但是,我最近更新了许多MVC和.NET NuGet程序包,现在,尽管项目在本地编译并可以正常运行,但是当我部署到Azure Web App时,调用API会返回不包含任何内容的实际HttpResponseMessage对象,而不是内容:
However, I recently updated a number of MVC and .NET NuGet packages, and now, while the project compiles and runs fine locally, when I deploy to an Azure Web App, calling the API returns the actual HttpResponseMessage object with no content, rather than the content:
{
"Version": {
"_Major": 1,
"_Minor": 1,
"_Build": -1,
"_Revision": -1
},
"Content": {
"Headers": [
{
"Key": "Content-Type",
"Value": [
"text/plain; charset=utf-8"
]
}
]
},
"StatusCode": 200,
"ReasonPhrase": "OK",
"Headers": [],
"RequestMessage": null,
"IsSuccessStatusCode": true
}
通常,同一调用将返回Content对象的JSON字符串.是否有一些奇怪的依赖问题发生,关于如何在不回滚所有nuget更新的情况下进行修复的任何想法?还是我需要更新Azure Web App上的设置(已经设置了.NET 4.7).
Normally this same call would return a JSON string of the Content object. Is there some odd dependency issue happening, any ideas on how to fix without rolling back all of the nuget updates? Or do I need to update a setting on the Azure Web App (already have .NET 4.7 set).
推荐答案
假设ApiController
,可以将操作重构为使用最新建议的语法.
Well assuming an ApiController
, the action can be refactored to use the more recent advised syntax.
[HttpPost]
public async Task<IHttpActionResult> GetData([FromBody]DataObject input) {
//.....code awaited here and gets 'returnModel'
return Ok(returnModel);
}
这篇关于在Azure Web App中的nuget更新之后,Web API返回HttpResponseMessage对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!