All I need to do is to modify [Connection]
HTTP Header from "Keep-alive" to lowercase "keep-alive".
I wrote the class,
public class PreRequestModifications
{
private readonly RequestDelegate _next;
public PreRequestModifications(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext context)
{
// Does not get called when making an HTTPWebRequest.
await _next.Invoke(context);
}
}
and registered on startup,
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseMiddleware<PreRequestModifications>();
}
but the Invoke
method does not get called when I execute await httpWebRequest.GetResponseAsync();