Open DavidBrower opened 3 years ago
Hi @DavidBrower, sorry for the delay: I fractured my clavicle, and was out for a bit.
You don't need to return a response: the proxy function does everything for you. Check out this sample.
[Route("api/google/{**rest}")]
public Task ProxyCatchAll(string rest)
{
// If you don't need the query string, then you can remove this.
var queryString = this.Request.QueryString.Value;
return this.HttpProxyAsync($"https://google.com/{rest}{queryString}");
}
For swagger purposes, I wanted to maintain the content model in the endpoint definition. Therefore I could manage to forward the content with the following code:
var httpProxyOptions = HttpProxyOptionsBuilder.Instance
.WithBeforeSend((c, hrm) =>
{
hrm.Content = new StringContent(JsonConvert.SerializeObject(requestModel), Encoding.UTF8, "application/json");
return Task.CompletedTask;
})
.Build();
I hope this helps someone.
I've been puzzling how to use AspNetCore.Proxy to forward a Post request to a Web API Controller. Currently, the code looks like this:
How would I rewrite this to use AspNetCore.Proxy?