java调用百度的api,通过ip定位 15C

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 }       
    报页面找不到,求大神指教

1个回答

你先试试你打开的地址,能不能在浏览器直接打开,你这种是爬虫形式 百度 地图有拦截的。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问