c# - How to clone a HttpRequestMessage when the original request has Content? -
I am trying to clone a request using the given method in this reply:
However, if I have content in the original request, then get an Object Dispatch option.
How can you clone HttpRequestMessage?
This should do the trick:
public static async works & lt ; HttpRequestMessage & gt; CloneHttpRequestMessageAsync (HttpRequestMessage Request) {HttpRequestMessage Clone = New HttpRequestMessage (req.Method, req.RequestUri); // Copy the content of the request (through memorystream) in the clone object var ms = new MemoryStream (); If (req.Content! = Null) {wait req.Content.CopyToAsync (ms) Configure (wrong); Ms.osition = 0; Clone.Source = New Stream Continent (MS); // Copy content headings if (req.Content.Headers! = Tap) foreach (var in req.Content.Headers) clone. Content Headers.Add (h.Key, h.Value); } Clone. Version = Rick Version; Foreign currency (keywalkueer & lt; strings, object & gt; support in rike properties) clone Properties Add (prop); Header in Foreach (keyvaluePair & lt; string, IEnumerable & lt; string & gt; reader) clones. Header. TRI AdByT Out validation (header, header.Value); Return clone; }
Comments
Post a Comment