如何获取httpurlconnection.getinputstream的编码方式
2个回答
2015-09-30
展开全部
先看一下要获取网页的编码方式 new InputStreamReader(inputStream)这个类有构造方法可以指定文字编码,把编码指定一下就行了。 比如GBK 编码的页面就BufferedReader br = new BufferedReader( new InputStreamReader(inputStream,"GBK")); UT
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
URL mUrl = new URL(url.substring(0, url.indexOf("?"))); //设置get请求访问的URI
conn = (HttpURLConnection) mUrl.openConnection();
conn.setRequestMethod("GET");
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
conn.setRequestProperty("Content-type","application/x-www-form-urlencoded;charset=UTF-8"); //解决乱码问题
---------------------------------------------------------
InputStream is = conn.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
conn = (HttpURLConnection) mUrl.openConnection();
conn.setRequestMethod("GET");
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
conn.setRequestProperty("Content-type","application/x-www-form-urlencoded;charset=UTF-8"); //解决乱码问题
---------------------------------------------------------
InputStream is = conn.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询