如何从 Apache HTTPClient 中的 HTTPRequest 获取 url 参数值

发布于 2024-11-12 10:21:52 字数 75 浏览 1 评论 0原文

我想获取查询字符串中特定参数的值。 HttpClient 中是否有任何方法可以为我做(例如 util 类方法)或者我必须编写自己的方法?

I would like to take value of specific parameter in query string. Is there any method in HttpClient which can do if for me (ex. util class method) or I have to write my own?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白芷 2024-11-19 10:21:52

在4.XX中有:

    List<NameValuePair> parameters = URLEncodedUtils.parse(new URI(
                request.getRequestLine().getUri()), HTTP.UTF_8);

        for (NameValuePair nameValuePair : parameters) {
            System.out.println(nameValuePair.getName() + ": "
                    + nameValuePair.getValue());
        }

然后处理你自己的参数。

In 4.X.X there is:

    List<NameValuePair> parameters = URLEncodedUtils.parse(new URI(
                request.getRequestLine().getUri()), HTTP.UTF_8);

        for (NameValuePair nameValuePair : parameters) {
            System.out.println(nameValuePair.getName() + ": "
                    + nameValuePair.getValue());
        }

Then handle your own parameter.

内心荒芜 2024-11-19 10:21:52

在 Apache Http Client 5.xx 中,URLEncodedUtils 已弃用。您可以使用:

      final List<NameValuePair> pairs = new URIBuilder(request.getUri()).getQueryParams();

默认情况下使用 UTF8 解码。

In Apache Http Client 5.x.x URLEncodedUtils is deprecated. You can use:

      final List<NameValuePair> pairs = new URIBuilder(request.getUri()).getQueryParams();

This uses UTF8 decoding by default.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文