安卓http
發表時間:2020-10-19
發布人:葵宇科技
浏覽次數:26
安卓經常應用http與辦事器(qì)交互,然則如(rú)不雅提交的數據有中(zhōng)文(wén),就經常出鍁氚搽。
1.起首将workbench編碼改成utf-8
2.将請求的url中(zhōng)的英文(wén)進行轉碼
3.拼接最終url,并請求
String test=URLEncoder.encode("羅占偉", "UTF-8"); String urlstring="http://luozhanwei1.app.com/bee/gata.php?name="+test; URL url=new URL(urlstring); HttpURLConnection urlConnection=(HttpURLConnection) url.openConnection(); InputStreamReader isr=new InputStreamReader(urlConnection.getInputStream(),"UTF-8" ); BufferedReader br=new BufferedReader(isr); result=br.readLine(); System.out.println(result);