ak和ip是我随便写的,我原码中写的是正确的
public static void main(String[] args) {
String add = "http://api.map.baidu.com/location/192.xxx.xxx.xxx?ak=dsfafdsffdsdsfdOVG9&coor=bd09ll";
try {
URL Url = new URL(add);
URLConnection conn = Url.openConnection();
conn.setRequestProperty("accept", "text/javascript");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("user-agent",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
conn.connect();
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String s;
String result = "";
while((s = in.readLine()) != null){
result += s;
}
System.out.println(result);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
<!DOCTYPE html><!--STATUS OK--><html><head> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta http-equiv="content-type" content="text/html;charset=utf-8"> <meta content="always" name="referrer"> <title>页面不存在_百度搜索</title> <style data-for="result"> body {color: #333; background: #fff; padding: 0; margin: 0; position: relative; min-width: 700px; font-family: arial; font-size: 12px }
报页面找不到,求大神指教