Does anyone have any experience with serializing HttpRequestMessage objects? Trying with Json.net and partially working. However, JsonConvert.DeserializeObject fails due to problems with the StringContent construct: "Unable to find constructor to use type System.Net.Http.StringContent."
The following is a summary: I want to save the web request and issue it later, in case of temporary network problems or service unavailability, etc.
Example failed code:
var request = new HttpRequestMessage(HttpMethod.POST, "http://www.something.com"); request.Headers.Date = DateTimeOffset.UtcNow; request.Headers.AcceptLanguage.Add(new System.Net.Http.Headers.StringWithQualityHeaderValue("en-US")); request.Content = new StringContent("Hello World!"); request.Content.Headers.Add("x-some", "thing"); var result = JsonConvert.SerializeObject(request, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Objects, TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Full }); var deserializeRequest = JsonConvert.DeserializeObject<HttpRequestMessage>(result, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Objects });
source share