c# - 如何从我的控制器向另一台服务器发送请求?
问题描述
我正在尝试从我的控制器向另一台服务器发送请求,但它没有返回结果......什么都没有。
[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);
解决方案
推荐阅读
- java - 在我的数据库 Java Derby 中插入新数据时生成的 ID 错误
- javascript - Brain.js GPU 慢速训练
- selenium - Selenium Webdriver Java-> 单击我想要的帖子的 Facebook 分享按钮
- java - 通过更新变量更改 LiveData 源
- python - 处理 post 请求的 Django Web 应用程序
- concurrency - Clojure - 检查延迟的第 n 个元素是否已实现
- javascript - Amcharts:具有多个系列的堆叠列
- c - get_string() 返回什么?
- python - 在无向图中找到长度为 4 的循环
- node.js - 在快递中,当它有破折号时如何从表单中获取属性名称?