Точка входа API выглядит следующим образом:
Код: Выделить всё
[HttpPost]
[Route("AddWorkReportToIssue")]
[Authorize(Roles = "webAPI_user")]
public BugNetWorkReports AddWorkReportToIssue(int issueId, string workReportComment, DateTime workDate, decimal duration, Guid userId)
400: «workReportComment является обязательным».
Фрагмент кода, отправляющий данные, выглядит следующим образом:
Код: Выделить всё
client = new HttpClient();
client.BaseAddress = new Uri(host);
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
token = await AuthenticateAsync(client, user);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", token);
BugNetAddWorkReport wr = new BugNetAddWorkReport();
wr.issueId = 2300; // int
wr.workReportComment = "This is a unit test"; // string
wr.workDate = new DateTime(2025, 11, 10); // datetime
wr.duration = 0.5M; // decimal
wr.userId = "5f2ab78f-2b9e-4e8d-8e78-1cedbc4bb49a"; // string
// all fields are filled...
var options = new JsonSerializerOptions() { PropertyNameCaseInsensitive = true };
var result = await client.PostAsJsonAsync("api/BugNet/AddWorkReportToIssue", wr, options);
Console.WriteLine("Inspect result here");
Код: Выделить всё
POST https:///api/BugNet/AddWorkReportToIssue HTTP/1.1
Host:
Accept: application/json
Authorization: bearer
Transfer-Encoding: chunked
Content-Type: application/json; charset=utf-8
{"issueId":2300,"workReportComment":"This is a unit test","workDate":"2025-11-10T00:00:00","duration":0.5,"userId":"5f2ab78f-2b9e-4e8d-8e78-1cedbc4bb49a"}
Код: Выделить всё
HTTP/1.1 400 Bad Request
Transfer-Encoding: chunked
Content-Type: application/problem+json; charset=utf-8
Server: Microsoft-IIS/10.0
X-Powered-By: ASP.NET
Date: Tue, 11 Nov 2025 14:43:11 GMT
{
"type": "https://tools.ietf.org/html/rfc9110#section-15.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"errors": {
"workReportComment": [ "The workReportComment field is required." ]
},
"traceId": "00-ffb71a47d567e6dbedaef18eea7d7dec-392595b93b4c51e7-00"
}
Изменить: добавлена дополнительная информация о моем успешном тестировании Swagger
Подробнее здесь: https://stackoverflow.com/questions/798 ... s-required
Мобильная версия