java后台访问url

阅读更多
中心编码问题是一个老问题了,一直没得到很好的解决,望大牛们指点迷津
public static String callUrlByGet(String callurl,String charset){
		
		String result = "";
		try {
			URL url = new URL(callurl);
			URLConnection connection = url.openConnection();
			connection.connect();
			
			BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(),charset));
			String line;
			while((line = reader.readLine())!= null){
				result += line;
				result += "\n";
			}
			
		} catch (Exception e) {
			e.printStackTrace();
			return "";
		}
		return result;
	}

你可能感兴趣的:(java,connection,urlconnection,url,charset)