私は現在、テストのために .NET Core Web App を使用した API に取り組んでおり、これに固執しています。
実際、私はこのコードを持っています:
namespace CoreWebApp.API.Admin
{
[Route("api/country")]
public class CountryController : Controller
{
// GET: api/country
[HttpGet]
public HttpResponseMessage Get()
{
List<Country> countries = Shared.Database.SqlAction.CountriesTable.GetCountries();
return new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(JsonConvert.SerializeObject(countries), Encoding.UTF8, "application/json") };
}
}
}
私がやろうとしているのは、 anHttpStatusCodeと anを返すことですHttpContent。次に、Postman でそれを取得する必要があります。
[
{
"Name":"France"
},
{
"Name":"Germany"
},
{
"Name":"Spain"
},
....
]
ステータスコード OK 200
しかし、私はこの体をまったく得ません。私が得るものがあります:
{
"version": {
"major": 1,
"minor": 1,
"build": -1,
"revision": -1,
"majorRevision": -1,
"minorRevision": -1
},
"content": {
"headers": [
{
"key": "Content-Type",
"value": [
"application/json; charset=utf-8"
]
}
]
},
"statusCode": 200,
"reasonPhrase": "OK",
"headers": [],
"requestMessage": null,
"isSuccessStatusCode": true
}
しばらく検索していますが、まだコンテンツ内のデータを取得できません。何が間違っていますか? これは私の最初の .NET Core Api ですので、アドバイスがあればお気軽にお寄せください :)
助けてくれてありがとう!