我正在使用HttpListener为在localhost上用另一种技术编写的应用程序提供Web服务器.该应用程序使用简单的表单提交(application/x-www-form-urlencoded)向我的软件发出请求.我想知道是否已经编写了一个解析器来将html请求文档的主体转换为哈希表或等效文件.
考虑到.NET已经提供了多少.NET,我发现自己很难相信我需要自己写这个.
提前致谢,
Gon*_*alo 25
你的意思是HttpUtility.ParseQueryString,它给你一个NameValueCollection?这是一些示例代码.您需要更多错误检查,并可能使用请求内容类型来确定编码:
string input = null;
using (StreamReader reader = new StreamReader (listenerRequest.InputStream)) {
input = reader.ReadToEnd ();
}
NameValueCollection coll = HttpUtility.ParseQueryString (input);
Run Code Online (Sandbox Code Playgroud)
如果您使用HTTP GET而不是POST:
string input = listenerRequest.Url.QueryString;
NameValueCollection coll = HttpUtility.ParseQueryString (input);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6764 次 |
| 最近记录: |