I have a Post method that returns an HttpResponseMessage
:
HttpResponseMessage response =
Request.CreateResponse(HttpStatusCode.Created, updatedItemDto);
I'm writing some tests for this and would like to get the updated item from the HttpResponseMessage
(particularly the ItemId
). I tried inspecting the object and it looks like the object lives in Response.Content
, but I don't know how to get it from the Content
.
If HttpResponseMessage contain serialized data model of a known class then you can use ReadAsAsync<>()
extension method like this
MyObject obj = await response.ReadAsAsync<MyObject>();
And this is the most simple and easy way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With