简体   繁体   English

C#Http服务器请求路由

[英]C# Http server requests routing

I'm writing HTTP server using HttpListener, that would manage following requests. 我正在使用HttpListener编写HTTP服务器,该服务器将管理以下请求。 Each of them should return corresponding JSON object. 它们每个都应返回相应的JSON对象。

GET /command1/command2/command3
GET /command1/<ip-port>/command3
GET /command4/command3
GET /command5/

and so on... 等等...
How should I manage this branching of commands? 我应该如何管理此命令分支?
It seems to me I can easily deal with this using regex. 在我看来,我可以使用正则表达式轻松处理此问题。 Or maybe I should choose some pattern like State? 还是我应该选择某种状态,例如“状态”?

You can check out Grapevine , which has this functionality built in. I'm the author of the library, but it's open source , so you can see how I manage routing by reviewing the source code (see src/Grapevine/Server). 您可以签出内置了此功能的Grapevine 。我是该库的作者,但它是开放源代码 ,因此您可以通过查看源代码来查看如何管理路由(请参阅src / Grapevine / Server)。 Or you can just use the library if it to meets your needs. 或者,只要满足您的需求,就可以使用该库。

https://sukona.github.io/Grapevine/en/getting-started.html https://sukona.github.io/Grapevine/en/getting-started.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM