最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

在Java中组合URL或URI的惯用方法是什么?

SEO心得admin38浏览0评论
本文介绍了在Java中组合URL或URI的惯用方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何在Java中构建URL或URI?有没有惯用的方法,或者很容易做到这一点的库?

How do I build a URL or a URI in Java? Is there an idiomatic way, or libraries that easily do this?

我需要允许从请求字符串开始,解析/更改各种URL部分(方案,主机,路径) ,查询字符串)并支持添加和自动编码查询参数。

I need to allow starting from a request string, parse/change various URL parts (scheme, host, path, query string) and support adding and automatically encoding query parameters.

推荐答案

使用HTTPClient运行良好。

Using HTTPClient worked well.

protected static String createUrl(List<NameValuePair> pairs) throws URIException{ HttpMethod method = new GetMethod("example"); method.setQueryString(pairs.toArray(new NameValuePair[]{})); return method.getURI().getEscapedURI(); }
发布评论

评论列表(0)

  1. 暂无评论