将查询参数传递给 Windows 上 Apache 中的 C# CGI 程序
我在 Windows 上的 Apache 中将 C# 程序作为 CGI 脚本运行,效果很好。但是,我现在尝试向其传递查询参数,例如
http://localhost/cgi-bin/csharp_program.exe?hello=kitty&goodbye=world
我知道我的查询参数将在 QUERY_STRING
环境变量中传递,例如
`hello=kitty&goodbye=world`
C# 中存在哪些函数/类来解析这些查询参数这样我就不需要重新发明轮子并自己做?
I'm running a C# program as a CGI script in Apache on Windows, which works just fine. However, I'm now trying to pass it query parameters, e.g.
http://localhost/cgi-bin/csharp_program.exe?hello=kitty&goodbye=world
I understand that my query parameters will be passed in the QUERY_STRING
environment variable, e.g.
`hello=kitty&goodbye=world`
What functions/classes in C# exist to parse these query parameters for me so that I don't need to reinvent the wheel and do it myself?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 System.Web.HttpRequest。在 .NET 3.5 中,它有一个公共构造函数,它接受文件、URL 和查询字符串。我从未在 CGI 进程中使用过它,但您可能可以伪造文件和 URL。然后您可以访问 QueryString 属性,它是一个 NameValueCollection。
您还可以采用反射路线并创建一个 HttpValueCollection(System.Web 内部)的实例,它是一个 NameValueCollection。
Check out System.Web.HttpRequest. In .NET 3.5 it has a public constructor that takes a file, URL, and query string. I've never used it in a CGI process, but you could probably fake the file and URL. Then you can access the QueryString property which is a NameValueCollection.
You could also go the reflection route and create an instance of HttpValueCollection (internal to System.Web) which is a NameValueCollection.