采用HttpURLConnection方式调用第三方接口,接口的返回值经过unicode编码处理

在接口的调用过程中,第三方接口的返回值使用unicode处理了,调用过程中一直报错

改成下面这样就可以了

public class TestStatic {
	public static void main(String[] args) throws Exception {
		getDatas();
	}
	public static void getDatas(){
		HttpURLConnection conn = null;
		try {
			String INFORMATION_URL = "http://250.250.250:8080/datasnap/rest/TInterFace/getoverdayreaderinfor";
			conn = getConnection(INFORMATION_URL, "GET");
			conn.setConnectTimeout(30000);  
			conn.setReadTimeout(30000);  
			conn.connect();
			String resp = ""; 
			try {
				BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));
				String next = null;
				while ((next = reader.readLine()) != null) {
					resp += next;
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			conn.disconnect();
			System.out.println(resp);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	private static HttpURLConnection getConnection(String urlString,String verb) {
		HttpURLConnection conn = null;
		try {
			URL url = new URL(urlString);
			conn = (HttpURLConnection)url.openConnection();
			conn.setRequestMethod(verb);
			conn.setDoInput(true);
			conn.setDoOutput(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return conn;
	}
}


已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页