-小太阳 2016-12-14 03:20 采纳率: 0%
浏览 1566
已结题

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

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条回答 默认 最新

  • hfmbook 2016-12-14 09:53
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥50 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗