简体   繁体   中英

HttpServletRequest get query parameters from a GET call

I'm trying to get the query parameter client_id from a GET call with a url like this:

https://example.com?client_id=aclient-id&param2=value2&param3=value3

I'm getting a null value for clientId when I try to get the query parameter, any ideas why this is happening?

HttpServletRequest httpRequest = (HttpServletRequest) request;
final String clientId = httpRequest.getParameter("client_id");

The other calls like http.getRequestURI() and http.getMethod return the expected values.

Please check what the string value of the client id that is actually being sent to the server. In your example you say clientId in your code you're looking for client_id , while they make semantic sense to humans, those are different values to a computer.

You can also take a peek at all the parameter values in your HttpServletRequest:

httpRequest.getParameterMap()
    .entrySet()
    .stream()
    .forEach(System.out::println);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM