将查询参数传递给 Windows 上 Apache 中的 C# CGI 程序

发布于 2024-08-03 20:15:24 字数 335 浏览 1 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谈情不如逗狗 2024-08-10 20:15:24

查看 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文