1. 程式人生 > >解決android http請求帶中文引數會亂碼(url編碼)

解決android http請求帶中文引數會亂碼(url編碼)

今天在用android 的
URL url = new URL("http://www.my400800.cn &search=400電話 ");
  HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
時傳遞到服務端的中文字元時亂碼,最後是將要傳送的字元經過編號就可以了程式碼修改如下:


URL url = new URL("http://www.my400800.cn &search="+java.net.URLEncoder.encode("400電話 "));
  HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();