【发布时间】:2021-01-05 22:19:04
【问题描述】:
假设我们有一个 API,它在其控制器操作之一中接收 URL。这在 Net Core 3.1 中如何实现?如果我理解正确,那么https://www.test.com/anothertest/test 会搞乱到控制器的路由吗?
下面的代码示例
[Route("api/[controller]")]
public class TestController : Controller
{
[HttpPost("{url}")]
public ActionResult<string> Post(string url)
{
// I want this to work! The url should be the full url specified i.e. https://www.myawesome.com/url/with/slashes
}
}
所以如果我调用 https://localhost:5001/api/Test/https://www.url.com/with/slashes 我会得到 https://www.url.com/with/slashes 作为传入的 url 参数。
【问题讨论】:
-
嗨@Tomato,你想获取url字符串吗?
标签: c# api asp.net-core controller asp.net-core-3.1