Updating Request Messages in ASP.NET Handlers and Modules

r.Headers.Add(“Accept”, “text/html”);

In an ASP.NET Web API handler, you’ll be able also replace the content of the incoming request message, like this:

request.Content = new System.Net.Http.StringContent(“{‘custid’:’A123′}”, Encoding.UTF8, “application/json”);

On the off chance that you utilize this strategy, the default show binding process won’t load the parameters in your Action method with the content you’ve just inserted into the message. You’ll need to write code like this in your Action method to recover that content:

public async Task Get(string Id)
string result = await Request.Content.ReadAsStringAsync();

The code to supplant the outgoing request message in a Web API message handler is comparative to the code to replace the incoming request:

resp.Content = new System.Net.Http.StringContent(“{‘custid’:’A124′}”, Encoding.UTF8, “application/json”);

Leave a Comment