如何从HttpListenerRequest获取表单参数? [英] How can I get form parameters from HttpListenerRequest?

查看:2068
本文介绍了如何从HttpListenerRequest获取表单参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 HttpListener 来实现一个非常简单的http服务器,它接受来自Java客户端的POST。当客户端调用时,我得到一个 HttpListenerRequest ,其中包含所有表单参数。如何提取表单参数?我似乎只能访问内容流....

I am using a HttpListener to implement a very simple http server, which is accepting a POST from a Java client. When the client calls I get a HttpListenerRequest, which contains all the form parameters. How can I extract the form parameters? I seem to have access only to the content stream....

推荐答案

HttpListener是一个低级组件,因为它是您为每个请求获取的HttpListenerRequest对象。通过POST发送的表单数据包含在正文中,因此您必须自己处理流并提取表单数据。 QueryString数据可供您使用,因为它是请求地址的一部分,并且不需要任何流处理来提取。这使它与表单数据区分开来,因为处理流IS是必需的。

HttpListener is a low-level component, as is the HttpListenerRequest object you get for each request. Form data sent via POST is contained within the body, so you will have to process the stream and extract the form data yourself. The QueryString data is available to you because that is part of the request address, and does not require any stream processing to extract. That differentiates it from the form data, as processing the stream IS required.

这篇关于如何从HttpListenerRequest获取表单参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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