httpservletrequest从get呼叫中获取查询参数
我正在尝试从具有如下网址的 GET 调用中获取查询参数 client_id
:
https://example.com?client_id=aclient-id¶m2=value2¶m3=value3
当我尝试获取查询时,我得到 clientId
的空值参数,有什么想法为什么会发生这种情况吗?
HttpServletRequest httpRequest = (HttpServletRequest) request;
final String clientId = httpRequest.getParameter("client_id");
其他调用(例如 http.getRequestURI()
和 http.getMethod
)返回预期值。
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¶m2=value2¶m3=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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请检查实际发送到服务器的客户端ID的字符串值。在您的示例中,您在您要寻找的代码中说
clientId
,而当它们对人的语义意义时,这些值与计算机是不同的值。您还可以查看httpservletrequest中的所有参数值:
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 forclient_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: