InputStream in = address.openStream();
URL url = new URL("://www.mydomain.com/?param1=NÃO¶m2=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ÃOpecial字符Ã正在逃脱 如何在不丢失char值的情况下使用它?
答案 0 :(得分:0)
我相信您希望使用URLEncoder.encode(String, String)
对参数进行编码,例如
try {
String value = URLEncoder.encode("NÃO", "utf-8");
String url = "://www.mydomain.com/?param1=" + value + "¶m2="
+ value;
System.out.println(url);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
输出
://www.mydomain.com/?param1=N%C3%83O¶m2=N%C3%83O