网络请求结果出现乱码,求指点怎么改

Android 码拜 7年前 (2017-04-16) 1107次浏览
	// 通过url获取数据
	public static String Getpath(String path) {
		StringBuffer buffer = new StringBuffer();
		URL url;
		try {
			url = new URL(path);
			HttpURLConnection connection = (HttpURLConnection) url
					.openConnection();
			InputStream stream = connection.getInputStream();
			byte[] by = new byte[1024];
			int len = 0;
			while ((len = stream.read(by)) != -1) {
				buffer.append(new String(by, 0, len, "UTF-8"));
			}
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		Log.e("TAG",  buffer.toString());
		return buffer.toString();
	}

log里面打印结果有乱码出现了,求指点

解决方案

10

可能不是urf-8 的格式

90

String str = new String(buffer.toString().getBytes(“iso8859-1″),”UTF-8”);

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明网络请求结果出现乱码,求指点怎么改
喜欢 (0)
[1034331897@qq.com]
分享 (0)