Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Microsoft.AspNetCore.Http.HttpRequest to HttpRequestMessage

I need to convert Microsoft.AspNetCore.Http.HttpRequest from an AspNetCore context to an HttpRequestMessage to pass to an HttpClient. Is there a simple way of achieve this? Or any hint to implement this would be very helpful.

Update I want to convert the request into a message but I want to change the target url, I want just to redirect the request into another server.

like image 860
yosbel Avatar asked Aug 18 '17 14:08

yosbel


1 Answers

Try Web API Compatibility Shim

HttpRequestMessageFeature hreqmf = new HttpRequestMessageFeature(httpRequest.HttpContext); HttpRequestMessage httpRequestMessage = hreqmf.HttpRequestMessage; 

Or you could get inspired by Microsoft.AspNetCore.Proxy

These extensions to httpContext may come in handy.

like image 174
Strenkor En'Triel Avatar answered Oct 14 '22 13:10

Strenkor En'Triel