У меня есть класс/модель с одним полем:
Код: Выделить всё
public class ResultsiMeter
{
[JsonProperty("id")]
[JsonPropertyName("id")]
public int id { get; set; }
}
Код: Выделить всё
[Route("api/[controller]")]
[HttpPost]
public void Post([FromBody] ResultsiMeter resultsiMeter)
{
return;
}
[HttpGet]
public IEnumerable Get()
{
return new string[] { "value1", "value2" };
}
Код: Выделить всё
GET http://localhost:63719/Api/iMeterResults HTTP/1.1
Accept-Encoding: gzip,deflate
Host: localhost:63719
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.5.5 (Java/16.0.2)
Когда я запускаю запрос POST
Код: Выделить всё
POST http://localhost:63719/Api/iMeterResults HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: application/json;charset=UTF-8
Content-Length: 19
Host: localhost:63719
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.5.5 (Java/16.0.2)
{
"id": 12345
}
Код: Выделить всё
application/problem+json; charset=utf-8, 185 bytes
{
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
"title": "Bad Request",
"status": 400,
"traceId": "00-7bf623aeedb0abf41a13dd0a5e87a045-48a6258679cea4d5-00"
}
JSON очень прост и, похоже, построен правильно.
Может ли кто-нибудь направить новичка-болвана на правильный путь, пока я в замешательстве?
Подробнее здесь: https://stackoverflow.com/questions/784 ... estful-api
Мобильная версия