1


Hello!
I have self host web proxy service
Need to Substitute host:port and to resend

public class HomeController : ApiController
{
    [HttpGet]
    public HttpResponseMessage Index()
    {
        using (HttpClient client = new HttpClient())
        {
            Request.RequestUri = new Uri($"http://{Settings.HOST}:{Settings.PORT}" + Request.RequestUri.AbsolutePath);
            Request.Headers.Host = $"{Settings.HOST}:{Settings.PORT}"; //Request.Headers.Host = new Uri($"http://{Settings.HOST}:{Settings.PORT}").Authority;
            Request.Properties["Via"] = $"http://{Settings.HOST}:{Settings.PORT}" + Request.RequestUri.AbsolutePath; //Request.Method = HttpMethod.Post;

            var data = client.SendAsync(Request).Result; // Exception: Cannot send a content-body with this verb-type
            return data;
        }
    }
}

StackTrace ProtocolViolationException:

in System.Net.HttpWebRequest.CheckProtocol(Boolean onRequestStream)
in System.Net.HttpWebRequest.BeginGetRequestStream(AsyncCallback callback, Object state)
in System.Net.Http.HttpClientHandler.StartGettingRequestStream(RequestState state)
in System.Net.Http.HttpClientHandler.PrepareAndStartContentUpload(RequestState state)

Any suggestions?

  • 1
    You are sending `this.Request` as a parameter to your `client`. You are not supposed to do this. `this.Request` represents the web request made to `Home/Index` - and it should not be passed to **another** http request like you are doing. Have a read of http://go.microsoft.com/fwlink/p/?LinkId=397535 . – mjwills Aug 25 '17 at 12:46
  • Did that help @MadMaxMobileMakerMoreM ? – mjwills Aug 25 '17 at 22:53

0 Answers0