InputStream in = address.openStream();
URL url = new URL("://www.mydomain.com/?param1=NÃO&param2=NÃO");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder result = new StringBuilder();
String line;
while((line = reader.readLine()) != null) {
    result.append(line);
}
System.out.println(result.toString());


但是,当我尝试将结果放入StringBuilder中时,NÃO特殊字符Ã已被转义
如何在不损失字符集值的情况下实现这一目标?

最佳答案

我相信您想使用URLEncoder.encode(String, String)对参数进行编码,例如

try {
    String value = URLEncoder.encode("NÃO", "utf-8");
    String url = "://www.mydomain.com/?param1=" + value + "&param2="
            + value;
    System.out.println(url);
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
}


输出是

://www.mydomain.com/?param1=N%C3%83O&param2=N%C3%83O

07-24 09:37