二_叔 2017-09-26 04:00 采纳率: 100%
浏览 2276
已采纳

百度鹰眼返回值问题,百度工程师您好

我用Java 调用百度鹰眼《实时位置搜索》 返回值是{"status":210,"message":"APP IP校验失败"},请问这是什么问题

public static final String yingYan_AK_S="******";

/**
 * 百度鹰眼serviceID
 */
public static final String yingyan_SERVICE_ID = "******";

public static final String yingyan_URL="http://yingyan.baidu.com/api/v3/";

/**
 * 百度鹰眼提交方式
 */
public static final String yingyan_POST="POST";
public static final String yingyan_GET="GET";

//创建entity,并赋属性信息
public static class yingyanEntity{

    public static final String SEARCH = "entity/search";

    public static final String BOUNDSEARCH = "entity/boundsearch";
    /**
     * 
     */
    public static final String AROUNDSEARCH = "entity/aroundsearch";
    /**
     * 检索符合条件的entity,返回entity属性信息和最新位置。可用于列出entity,也可用于批量查询多个entitiy的位置
     */
    public static final String DISTRICTSEARCH = "entity/districtsearch";


}

public static String yingyanReq(String urlReq, String param, String method) {
    try {
        //Get请求,拼装参数
        if (yingyan_GET.equals(method)) {
            urlReq = urlReq + "?" + param;
        }
        //创建URL对象
        URL url = new URL(urlReq);
        //返回一个URLConnection对象,它表示到URL所引用的远程对象的连接
        URLConnection urlConnection = url.openConnection();
        //POST请求,写入参数
        if (yingyan_POST.equals(method)) {
            // 设置doOutput属性为true表示将使用此urlConnection写入数据
            urlConnection.setDoOutput(true);
            // 定义待写入数据的内容类型,我们设置为application/x-www-form-urlencoded;charset=UTF-8"类型
            urlConnection.setRequestProperty("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
            // 得到请求的输出流对象
            OutputStreamWriter out = new OutputStreamWriter(urlConnection.getOutputStream());
            // 把数据写入请求的Body
            out.write(param);
            out.flush();
            out.close();
        }
        InputStream inputStream = urlConnection.getInputStream();
        String encoding = urlConnection.getContentEncoding();
        String result = IOUtils.toString(inputStream, encoding);
        System.out.println(result);
        return result;
    }catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
        return null;
    }

}

public static void main(String[] args) {

    String urlReq = yingyan_URL + yingyanEntity.DISTRICTSEARCH;
    String param = "ak="+YingYan_AK_S+"&service_id="+yingyan_SERVICE_ID+"&keyword=海淀区";

    yingyanReq(urlReq, param, yingyan_GET);
}
  • 写回答

2条回答 默认 最新

  • 二_叔 2017-09-26 09:53
    关注

    谢谢已经解决了,service哪里没有添加白名单

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • MR_WRONG_Man 2017-09-26 06:20
    关注

    代码没问题,估计别人那边配置了IP名单的!

    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 我用C语言easyx图形库绘制了一个3d游戏方框透视,但进入游戏时候鼠标准星对准方框边缘 鼠标光标就会弹出来这是啥情况怎样让光标对准绘制的方框点击鼠标不弹出光标好烦这样
  • ¥20 用Power Query整合的问题
  • ¥20 基于python进行多背包问题的多值编码
  • ¥15 相同型号电脑与配置,发现主板有一台貌似缺少了好多元器件似的,会影响稳定性和使用寿命吗?
  • ¥15 要求编写稀疏矩阵A的转置矩阵的算法
  • ¥15 编写满足以下要求的停车场管理程序,设停车场只有一个可停放n辆车的狭窄通道且只有一个大门可供车辆进出。
  • ¥15 C语言:数据子序列基础版
  • ¥20 powerbulider 导入excel文件,显示不完整
  • ¥15 用keil调试程序保证结果进行led相关闪烁
  • ¥15 paddle训练自己的数据loss降不下去