php文件存在h盤 服務器中,由於記事本默認編碼ascII 導致android端使用 ,UrlHttpConnection類的 GET方法後, 獲取反饋(echo‘測試文本:登陸成功+123abc’)文本數據時“
@Override
public void run() {
{ Looper.
prepare()
; super.run()
; try { URL url =
new URL(
"http://192.168.1.109/mytest/index.php?name=" +
user +
"&psw=" +
passwd)
; HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection()
; InputStreamReader isr =
new InputStreamReader(urlConnection.getInputStream())
; BufferedReader br =
new BufferedReader(isr)
; String readbr
; while ((readbr = br.readLine()) !=
null)
line += readbr +
"\n";//下面的操作都多此一舉 // byte[] byteline = org.apache.commons.codec.binary.Base64.decodeBase64(line.getBytes()); //// Base64.
decode(
line,1) ////
line =
new String(byteline
,"utf8")
; //二進制轉到字符稱爲編碼,由字符到二進制稱爲解碼 //str.getBytes("charset");//指定charset,即用底層存儲的Unicode碼來解析 charset這種編碼格式的字節數組方式 //str.getBytes(); 如果括號中不寫charset,則採用的是Sytem.getProperty("file.encoding"),即當前文件的編碼方式, //Base64.decode(line.getBytes("utf8")); urlConnection.disconnect()
;//關閉http連接 }
catch (UnknownHostException e) { e.printStackTrace()
; line += e.toString()
; }
catch (IOException e) { e.printStackTrace()
; line += e.toString()
; }
finally { Log.
i(
"Mactivity_Thread", "line = " +
line)
; Message msg =
new Message()
; // msg.set msg.
obj =
new String(
line)
; mHandler.sendMessage(msg)
; Looper.
loop()
; }}
Android activity調用handler獲取 msg.obj.toString() 時,所得值顯示爲亂碼;多次轉換編碼無果,後改變 記事本的編碼,成功!