1


你好!
我有自托管网络代理服务
需要替换主机:端口并重新发送

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:

在 System.Net.HttpWebRequest.CheckProtocol(布尔 onRequestStream)
在 System.Net.HttpWebRequest.BeginGetRequestStream(AsyncCallback 回调,对象状态)
在 System.Net.Http.HttpClientHandler.StartGettingRequestStream(RequestState 状态)
在 System.Net.Http.HttpClientHandler.PrepareAndStartContentUpload(RequestState 状态)

有什么建议么?

4

0 回答 0