是否有一个.NET现成的方法来处理的HttpListener HttpListenerRequest身体反应的身体? [英] Is there a .NET ready made method to process response body of a HttpListener HttpListenerRequest body?
问题描述
我使用的HttpListener提供一个Web服务器写在另一种技术在本地主机上的应用程序。该应用程序是使用简单的表单提交(应用程序/ x-WWW的形式urlen codeD),使其请求我的软件。我想知道是否有已经写入HTML请求文档的正文转换成一个哈希表或等同解析器。
I'm using HttpListener to provide a web server to an application written in another technology on localhost. The application is using a simple form submission (application/x-www-form-urlencoded) to make its requests to my software. I want to know if there is already a parser written to convert the body of the html request document into a hash table or equivalent.
我觉得很难相信,我需要写我自己,给多少.NET似乎已经提供了。
I find it hard to believe I need to write this myself, given how much .NET already seems to provide.
在此先感谢,
推荐答案
您的意思是这样 HttpUtility.ParseQueryString ,让你的NameValueCollection?下面是一些示例code。你需要更多的错误检查和可能使用请求的内容类型,以找出编码:
You mean something like HttpUtility.ParseQueryString that gives you a NameValueCollection? Here's some sample code. You need more error checking and maybe use the request content type to figure out the encoding:
string input = null;
using (StreamReader reader = new StreamReader (listenerRequest.InputStream)) {
input = reader.ReadToEnd ();
}
NameValueCollection coll = HttpUtility.ParseQueryString (input);
如果你使用HTTP GET而不是POST:
If you're using HTTP GET instead of POST:
string input = listenerRequest.Url.QueryString;
NameValueCollection coll = HttpUtility.ParseQueryString (input);
这篇关于是否有一个.NET现成的方法来处理的HttpListener HttpListenerRequest身体反应的身体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!