Get Posted XML from HttpServletRequest Object

前端 未结 1 668
孤独总比滥情好
孤独总比滥情好 2021-01-04 22:12

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 ge

相关标签:
1条回答
  • That depends on how the client has sent it.

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

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

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

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

    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();
    // ...
    

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

    0 讨论(0)
提交回复
热议问题