从HttpServletRequest对象获取发布的XML [英] Get Posted XML from HttpServletRequest Object

查看:117
本文介绍了从HttpServletRequest对象获取发布的XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个接收HttpServletRequest的Filter,请求是一个POST,它包含一个我需要读入我的filter方法的xml。从HttpServletRequest对象获取已发布的xml的最佳方法是什么。

I have a Filter that receives the HttpServletRequest and the request is a POST that consists of an xml that I need to read into my filter method. What is the best way to get the posted xml from the HttpServletRequest object.

推荐答案

这取决于客户的发送方式。

That depends on how the client has sent it.

如果它是作为原始请求体发送的,那么使用 ServletRequest#getInputStream()

If it's been sent as the raw request body, then use ServletRequest#getInputStream():

InputStream xml = request.getInputStream();
// ...

如果它是作为常规 application / x-www-form-urlencoded 请求参数,然后使用 ServletRequest#getParameter()

If it's been sent as a regular application/x-www-form-urlencoded request parameter, then use ServletRequest#getParameter():

String xml = request.getParameter("somename");
// ...

如果它是作为上传的文件发送的 multipart / form-data part,然后使用 HttpServletRequest#getPart()

If it's been sent as an uploaded file in flavor of a multipart/form-data part, then use HttpServletRequest#getPart().

InputStream xml = request.getPart("somename").getInputStream();
// ...

这是标准servlet API支持的方式。其他方式可能需要不同的或第三方API(例如SOAP)。

That were the ways supported by the standard servlet API. Other ways may require a different or 3rd party API (e.g. SOAP).

这篇关于从HttpServletRequest对象获取发布的XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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