gpt4 book ai didi

c# - 如何使用 URI 而不是查询字符串在 ServiceStack 中使用预定义路由?

转载 作者:行者123 更新时间:2023-11-30 17:29:55 26 4
gpt4 key购买 nike

在 ServiceStack 中是否可以(如果可以,如何)使用带有 URI 中参数的预定义路由?我可以做一个或另一个,但将两者结合起来似乎不起作用:

[Route("/hello/{Name}")]

// ok
1. /hello/myname
2. /json/reply/hello
3. /json/reply/hello?Name=myname

// not ok
4. /json/reply/hello/myname
"The operation 'myname' does not exist for this service"

尝试了这些但都没有用:

[Route("/*/hello/{Name}")]
[Route("/{*}/hello/{Name}")]

特别是,为什么 3 有效,而 4 无效?谢谢!

最佳答案

不,ServiceStack's pre-defined routes 不可自定义并遵循明确的格式:

/{format}/[reply|oneway]/{servicename}

即您可以定义自己的自定义路由,但您不能更改保持其预定义行为的预定义路由。

要在 URL 上发送参数,您需要使用 queryString,例如:

 /json/reply/Hello?name=myname

否则,您可以使用 ServiceStack 支持的其他方法发送参数,例如序列化的 Request Body、FormData、HTTP Headers 等

关于c# - 如何使用 URI 而不是查询字符串在 ServiceStack 中使用预定义路由?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50600387/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com