Thanks for your help, I am writing a web API (using dotnet core 3) that accepts network errors report :
{
"sampling_fraction": 1.0,
"server_ip": "192.0.2.1",
"protocol": "http/1.1",
"method": "GET",
"request_headers": {
"If-None-Match": ["01234abcd"]
},
"response_headers": {
"ETag": ["01234abcd"]
},
"status_code": 304,
"type": "ok"
}
And trying to get request_headers
and response_headers
as collections of strings with values coming from HeaderNames class. Roughly
class Data
{ ...
public string Method {get;set;}
public List<string> RequestHeaders {get;set;}
public List<string> ResponseHeaders {get;set;}
}
So far I have created a Model Class to Cast it:
public class ErrorBody
{
public double Sampling_Fraction { get; set; }
public string Server_Ip { get; set; }
public string Protocol { get; set; }
public string Method { get; set; }
public HttpRequestHeader Request_Headers { get; set; }
public HttpResponseHeaders Response_Headers { get; set; }
public int Status_Code { get; set; }
public string Type { get; set; }
}
From Json I am trying to cast "Request_Headers" and "Response_Headers" as a collection of Headers, like:
public HttpRequestHeader Request_Headers { get; set; }
public HttpResponseHeaders Response_Headers { get; set; }
unsing System.Net
But the casting fails with error:
"errors": {
"$.body.request_headers": [
"The JSON value could not be converted to System.Net.HttpRequestHeader. Path: $.body.request_headers | LineNumber: 9 | BytePositionInLine: 24."
]
}
My method looks like:
[HttpPost]
public IActionResult CreateReport(ErrorDto error)
{
Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(error));
return Ok();
}
I am trying to cast both objects into a collection of HeaderName