问题
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))
};
}
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
}
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).
回答1:
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);
}
来源:https://stackoverflow.com/questions/51969826/web-api-returning-httpresponsemessage-object-after-nuget-updates-in-azure-web-ap