安卓http
发表时间:2020-10-19
发布人:葵宇科技
浏览次数:45
安卓经常应用http与办事器交互,然则如不雅提交的数据有中文,就经常出锨氚搽。
1.起首将workbench编码改成utf-8
2.将请求的url中的英文进行转码
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);