Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the Raw Request String from HttpServletRequest

Tags:

java

servlets

jsf

Is it possible to get the raw HTTP Request from the HttpServletRequest object? I want to see the raw request as a String if at all possible.

I need to get the full text of the request, in this case it's a POST request, so the URL doesn't help. It's also part of a multi-part form, so I can't just call the "getParameterNames()" or "getParameterValues()".

Thank you,

like image 490
Jaime Garcia Avatar asked Aug 27 '09 16:08

Jaime Garcia


People also ask

How do I request a full URL?

String getRequestURI() -Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request. java. lang. StringBuffer getRequestURL() -Reconstructs the URL the client used to make the request.

What is request getInputStream ()?

ServletInputStream. getInputStream() Retrieves the body of the request as binary data using a ServletInputStream . java.lang.String.

What is HttpServletRequestWrapper in Java?

public HttpServletRequestWrapper(HttpServletRequest request) Constructs a request object wrapping the given request. Throws: java.lang.IllegalArgumentException - if the request is null.

What is request getHeader?

getHeader. java.lang.String getHeader(java.lang.String name) Returns the value of the specified request header as a String . If the request did not include a header of the specified name, this method returns null . If there are multiple headers with the same name, this method returns the first head in the request.


1 Answers

You can read the raw HTTP request by doing:

ServletInputStream in = request.getInputStream();

and then use the regular readmethods of the InputStream.

Hope that helps.

like image 84
monchote Avatar answered Oct 07 '22 17:10

monchote