Best way to have one Web API forward request to other

后端 未结 2 1064
自闭症患者
自闭症患者 2021-01-30 18:31

I have a few web services running on different servers, and I want to have one web service running \"in front\" of the rest to decide which web service (server) the request shou

2条回答
  •  难免孤独
    2021-01-30 19:24

    Just run into the same task and have to add some more lines in addition to Yazan Ati answer.

        [HttpPost]
        [HttpGet]
        [Route("api/TestBot/{*remaining}")]
        public Task SendMessage()
        {
            const string host = "facebook.botframework.com";
            string forwardUri = $"https://{host}/api/v1/bots/billycom{Request.RequestUri.Query}";
    
            Request.Headers.Remove("Host");
            Request.RequestUri = new Uri(forwardUri);
            if (Request.Method == HttpMethod.Get)
            {
                Request.Content = null;
            }
    
            var client = new HttpClient();
            return client.SendAsync(Request, HttpCompletionOption.ResponseHeadersRead);
        }
    

提交回复
热议问题