I'm currently receiving a request through the WebApi, and trying to just resend it to another site.
The goal is to receive a request, by example: http://localhost:9999/#q=test. And then forward it to the real site:(for my test I set google.com) http://google.com/#q=test
I've the following code:
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
{
string url = request.RequestUri.PathAndQuery;
UriBuilder forwardUri = new UriBuilder(_otherWebSiteBase);
forwardUri.Path = url;
if (request.Method == HttpMethod.Get)
{
//request.Method = HttpMethod.Post;
}
request.RequestUri = forwardUri.Uri;
request.Headers.Host = forwardUri.Host;
return await _client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);//_client is an HttpClient
}
Currently I got an System.Net.ProtocolViolationException
which states:
Cannot send a content-body with this verb-type.
But my input request is a GET request(and should be a GET request). If I put a POST request, I don't have an exception anymore, but google says that they don't expect a POST request.
So why is this exception coming? Any idea on how to fix it?