【发布时间】:2019-05-22 17:24:44
【问题描述】:
我正在使用 HttpClient 调用 2 个 API(一个是原始的,一个是模拟的)。
因此,如果 API 调用的 URL 是 https://something.com/abc/xyz,当我在响应中 POST 到此 URL 时,RequestMessage.RequestUri 具有特定值,即 https://something.com/mno/eee?key=asdad。
为了复制这种行为,我设置了一个 web api 控制器 -
public class JqPay2Controller : ApiController
{
[HttpPost]
[ActionName("donotcare")]
public HttpResponseMessage DoNotCare()
{
var uri = new Uri("https://localhost:3232/mno/eee?key=asdad");
var contentStr = $"donotcare";
var res = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(contentStr),
RequestMessage = new HttpRequestMessage(HttpMethod.Post, uri)
};
return res;
}
}
我的应用程序将以模拟模式调用,我希望在 RequestMessage.RequestUri 属性中看到相同的值。
但我没有看到它,而是在我希望看到https://localhost:3232/mno/eee?key=asdad 时看到了https://something.com/abc/xyz。
我不确定这是如何工作的?我在这里做错了什么?
【问题讨论】:
标签: c# asp.net-mvc asp.net-web-api httpclient