如何从控制器发送请求到另一台服务器?

时间:2019-07-01 14:23:05

标签: c# httpclient asp.net-core-webapi

我正在尝试将控制器中的请求发送到另一台服务器,但是它不会返回结果……一无所有。

   [Route("api/[controller]")]
    [ApiController]
    public class GetPriceController : ControllerBase
    {
        // GET api/values
        [HttpGet]
        public async Task<ActionResult<string>> Get()
        {
var handler = new HttpClientHandler();
            handler.ClientCertificates.Add(new X509Certificate2(@"client.pfx", "password"));

            var HttpCl = new HttpClient(handler);

            var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, "https://foobar.com:777")
            {
                Content = new StringContent("data")
            };

            var response = await HttpCl.SendAsync(httpRequestMessage);
            return await response.Content.ReadAsStringAsync();
        }
    }

在SendAsync命令之后,什么也没发生。

   var response = await HttpCl.SendAsync(httpRequestMessage);

0 个答案:

没有答案
相关问题