After migrating our web API from the. NET Framework to. NET Core 1.1, you encounter a problem.
Previously, a Web API with a value type of Httpresponsemessage was returned, such as:
[HttpGet] Public Async Task Get () { returnawait _httpclient.getasync ($" ... " );}
(Note: The purpose of this Web API is to directly return the results of the HttpClient call back-end Web API to the calling client)
It would have returned the business data in JSON format, and now the JSON serialized data for Httpresponsemessage itself was returned:
{ "version": {}, " content": {}, "StatusCode": $, "reasonphrase": "OK", "headers": [], " Requestmessage ": { " version ": {}, " content ": null, " method ": {" method ":" GET "}, " RequestUri ":" ", "Headers": [], "Properties": {} }, "Issuccessstatuscode": true}
A donkey's head is not a horse's mouth.
The solution was later found on StackOverflow--asp.net Core httprequestmessage returns strange JSON message, which was successfully resolved with the method in question.
Here's how to fix it:
1) Add the following configuration in. csproj in order to install the NuGet package in step 2nd (ASP. NET Core 2.0 does not need to add this configuration)
< Packagetargetfallback >$ (packagetargetfallback);p ortable-net45+win8</packagetargetfallback>
2) Install NuGet package Microsoft.AspNetCore.Mvc.WebApiCompatShim
3) in Startup---Configureservices, add addwebapiconventions () after Addmvc () to:
Public void configureservices (iservicecollection services) { services. Addmvc (). Addwebapiconventions ();}
The ASP. NET Core Web API handles the issue of httpresponsemessage type return values