什么是正确的URLencoder编码转为“%22?

时间:2012-11-07 16:03:36

标签: java urlencode apache-httpclient-4.x

我有以下网址:

https://api-test.company.com/contacts?q=email= “jlowder@company.com”

我使用以下方法解析它:

String URL = "https://api-test.company.com/contacts?" + URLEncoder.encode("q=email=jlowder@company.com", "UTF-8");

我也试过“ISO-8859-1”,但两者都为我的网址返回:

https://api-test.homeaway.com/contacts?q%3Demail%3Djlowder%40homeaway.com

为了从我的服务器接收正确的响应,我需要网址为:

https://api-test.company.com/contacts?q=email=%22jlowder@company.com%22

%22是电子邮件地址周围的“”标记。

如何构建正确的网址?我找不到的例子都没有这样做..

1 个答案:

答案 0 :(得分:1)

如果你真的想要这个,那么你必须将引号也放入字符串中:

String URL = "https://api-test.company.com/contacts?q=email=" + URLEncoder.encode("\"jlowder@company.com\"", "UTF-8");

给出:     https://api-test.company.com/contacts?q=email=%22jlowder%40company.com%22

btw。:您想要命名字符串url,而不是URL