UnsupportedEncodingException: at sun.nio.cs.StreamDecoder.forInputStreamReader

知行合一1 发布于 2016/06/13 10:02
阅读 351
收藏 0
java.io.UnsupportedEncodingException: 
at sun.nio.cs.StreamDecoder.forInputStreamReader(StreamDecoder.java:71)
at java.io.InputStreamReader.<init>(InputStreamReader.java:100)
at com.fz.util.HttpClientUtils.connctionURL_Params(HttpClientUtils.java:93)
at com.fz.util.IpUtils.getIpAddr(IpUtils.java:23)

at com.fz.util.IpUtils.main(IpUtils.java:152)


	public String connctionURL_Params(String url, String method, String params) {
		StringBuffer bufferRes = new StringBuffer();
//		url = url + params;
		try {
			URL realUrl = new URL(url);
			HttpURLConnection conn = (HttpURLConnection) realUrl.openConnection();
			// 请求方式
			conn.setRequestMethod(method);
			conn.setDoOutput(true);
			conn.setDoInput(true);
			conn.setUseCaches(false);
            conn.setInstanceFollowRedirects(true);
            conn.setRequestProperty("Content-Type", "application/json");
//            conn.setRequestProperty("Charsert", "UTF-8");
//            conn.setRequestProperty("Charsert", "GBK");
//            conn.setRequestProperty("Charsert", "utf-8");
//            conn.setRequestProperty("connection", "keep-alive");
            
//            conn.setRequestProperty(HttpMethodParams.USER_AGENT,"Mozilla/5.0 (Linux; U; Android 4.0; en-us; GT-I9300 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30");
			conn.connect();

			InputStream in = conn.getInputStream();
			BufferedReader read = new BufferedReader(new InputStreamReader(in,params));
			String valueString = null;
			while ((valueString = read.readLine()) != null) {
				bufferRes.append(valueString);
			}
			read.close();
			in.close();
			in = null;
			if (conn != null) {
				// 关闭连接
				conn.disconnect();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return bufferRes.toString();
	}



加载中
返回顶部
顶部