在 [获取( "{route}" )] 上重新拟合变量



我在使用变量作为Get请求的路径时遇到了麻烦

这是一个超级简单的Get请求

public interface IParceriaIntegracao
{
[Get("/{caminho}")]
Task<IntegracaoResponse> GetShow(string caminho);
}

这是我的控制器

[HttpGet]
[Route("integrar")]
public async Task<IActionResult> GetShow(string url)
{
try
{
Uri uri = new Uri(url);
string hostCompleto = $"{uri.Scheme}://{uri.Host}";
string caminho = $"{uri.AbsolutePath.Substring(1)}";
var host = RestService.For<IParceriaIntegracao>(hostCompleto);
var retorno = await host.GetShow(caminho);
return await Response(retorno.Message);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}

主机运行正常没有问题,理论上路径的其余部分也应该如此。我尝试了使用和不使用子字符串,以及在Get注释中使用和不使用/。

但是它返回错误404,因为我的路径似乎不能正常工作。

你知道它可能是什么吗,或者我该怎么解决?

似乎您正在尝试访问路由,例如{baseAdress}/controller/integrar。因此,要访问此路由,还必须在接口中输入路由integrar,如下所示:

public interface IParceriaIntegracao
{
[Get("/integrar")]
Task<IntegracaoResponse> GetShow(string caminho);
}

最新更新