在 Android doGet方法中于老师一样但仍然乱码?
doGet方法中,为什么使用了 URLEncoder.encode(name,"utf-8")进行中文转码但在手机客户端输入中文,在控制台上任然是乱码?
private void doGet(){
try {
//中文字符转码 URLEncoder.encode(name,"utf-8")
url=url+"?name="+URLEncoder.encode(name,"utf-8")+"&age="+age;
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
URL httpUrl=new URL(url);
HttpURLConnection conn=(HttpURLConnection) httpUrl.openConnection();
conn.setRequestMethod("GET");
conn.setReadTimeout(5000);
BufferedReader reader=new BufferedReader(new InputStreamReader(conn.getInputStream()));
String str;
StringBuffer sb=new StringBuffer();
while ((str=reader.readLine())!=null) {
sb.append(str);
}