在Java中组合URL或URI的惯用方法是什么? [英] What is the idiomatic way to compose a URL or URI in Java?
本文介绍了在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("http://example.org");
method.setQueryString(pairs.toArray(new NameValuePair[]{}));
return method.getURI().getEscapedURI();
}
这篇关于在Java中组合URL或URI的惯用方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文