从HttpListener解析POST参数 [英] Parse POST parameters from HttpListener

查看:1567
本文介绍了从HttpListener解析POST参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有HttpListener。它听一些端口和IP。当我发送POST请求时它会抓住它。如何从HttpListenerRequest解析POST参数?

  HttpListenerContext context = listener.GetContext(); 
HttpListenerRequest request = context.Request;

if(request.HttpMethod ==POST)
{
//这里我可以读取字符串中的所有参数但是如何解析每个参数我不知道
}


解决方案

POST正文(从使用您选择用POST编码POST数据的任何机制来解析HttpListenerRequest上的InputStream。



例如,您可以使用JavaScript上的JSON.stringify调用发送JSON浏览器中的对象。在这种情况下,您可以使用.Net或JSON.Net中的JSON反序列化器。



或者,您可以选择完全发送XML,CSV或其他内容。 / p>

希望有所帮助 - 哈罗德


Let's say i have HttpListener. It listen some port and ip. When i send POST request it catch it. How can i parse POST parameters from HttpListenerRequest?

HttpListenerContext context = listener.GetContext();
HttpListenerRequest request = context.Request;

if ( request.HttpMethod == "POST" )
{
  // Here i can read all parameters in string but how to parse each one i don't know                                            
}

解决方案

The POST body (read from the InputStream on the HttpListenerRequest) is parsed using whatever mechanism you choose to encode the POST data with.

For example, you could be sending JSON using JSON.stringify calls on a JavaScript object in a browser. In that case you could use the JSON deserializer in .Net or JSON.Net.

Or, you might choose to send XML, or CSV, or something else entirely.

Hope that helps - Harold

这篇关于从HttpListener解析POST参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆