以百度天气接口测试
public static void main(String[] args) throws IOException {
String ak = "自己的AK";
String getURL = "http://api.map.baidu.com/telematics/v3/weather?output=json&location=西安&ak="+ak;
//解决中文传输乱码
getURL = new String(getURL.getBytes("UTF-8"));
URL url = new URL(getURL);
HttpURLConnection connect = (HttpURLConnection) url.openConnection();
connect.connect();
BufferedReader reader = new BufferedReader(new InputStreamReader(
connect.getInputStream(),"utf-8"));
String lines;
StringBuffer temp = new StringBuffer();
while ((lines = reader.readLine()) != null) {
temp.append(lines);
}
reader.close();
connect.disconnect();
将字符串以UTF-8的形式传入URL中
getURL = new String(getURL.getBytes("UTF-8"));
URL url = new URL(getURL);