Convert HttpRequestMessage to HttpRequest

2020-07-02 08:24发布

问题:

I'm converting ASP.NET web application to MVC Web Api project. One of my methods expects HttpRequest class. However, Web Api controller holds only HttpRequestMessage (this.Request) object. Do you know how I can convert HttpRequestMessage to HttpRequest?

回答1:

You probably don't need to convert from HttpRequestMessage. There is another way:

var context = new HttpContextWrapper(HttpContext.Current);
HttpRequestBase request = context.Request;


回答2:

Try to use/create a HttpRequestWrapper using your HttpRequestBase.