开发者社区 > 视觉智能 > 文字识别 > 正文

文字识别OCR中,身份证识别的。账号授权了ocr管理员权限了。为什么调用报错?

文字识别OCR中,身份证识别的,账号授权了ocr管理员权限了,但是调用报错,求助

    Map<String, String> headers = new HashMap<String, String>();
    //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
    headers.put("Authorization", "APPCODE " + appcode);
    //根据API的要求,定义相对应的Content-Type
    headers.put("Content-Type", "application/json; charset=UTF-8");

    Map<String, String> querys = new HashMap<String, String>();
    // 对图像进行base64编码
    String imgBase64 = img_base64(imgFile);

    //configure配置
    JSONObject configObj = new JSONObject();
    configObj.put("side", "face");

    String config_str = configObj.toString();

    // 拼装请求body的json字符串
    JSONObject requestObj = new JSONObject();
    requestObj.put("image", imgBase64);
    if(configObj.size() > 0) {
        requestObj.put("configure", config_str);
    }
    String bodys = requestObj.toString();

    try {
        HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
        int stat = response.getStatusLine().getStatusCode();
        if(stat != 200){
            System.out.println("Http code: " + stat);
            System.out.println("http header error msg: "+ response.getFirstHeader("X-Ca-Error-Message"));
            System.out.println("Http body error msg:" + EntityUtils.toString(response.getEntity()));
            return false;
        }

        String res = EntityUtils.toString(response.getEntity());
        JSONObject res_obj = JSON.parseObject(res);

        System.err.println(res_obj.toJSONString());
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;

展开
收起
想去床上睡觉 2024-07-01 11:40:59 16 0
3 条回答
写回答
取消 提交回答

文字识别技术可以灵活应用于证件文字识别、发票文字识别、文档识别与整理等行业场景,满足认证、鉴权、票据流转审核等业务需求。

相关电子书

更多
阿里云智能-印刷文字识别OCR-产品介绍 立即下载
阿里巴巴读光OCR 立即下载
印刷文字识别算法设计与在线服务 立即下载