开发者社区> 问答> 正文

在阿里云OpenAPI开启sdk代理之后报错,怎么解决?

在阿里云OpenAPI开启sdk代理之后报错,怎么解决?
Protocol: https
Port: null
POST /
Query:
Url: https://uat-oss.huarunbao.com/emall-dev-open/rest/banner/6a3e5b3e4860ba897dd5209acc735ffb/ED0E2B3D830F43369420B31FFFBBF478.png
Headers:
Authorization: ACS3-HMAC-SHA256 Credential=LTAI5t8zFbSYpQvQsgW68tav,SignedHeaders=host;x-acs-action;x-acs-content-sha256;x-acs-date;x-acs-signature-nonce;x-acs-version,Signature=f085108f840bc93e8401cd3ba5772ecc00b7426fa7edc90ac4f6be68eb677997
x-acs-action: RecognizeVehicleLicense
host: ocr-api.cn-hangzhou.aliyuncs.com
x-acs-date: 2023-12-08T09:22:53Z
x-acs-version: 2021-07-07
x-acs-content-sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
x-acs-signature-nonce: da91430b0e97aa1bd473f8648d7c7b11
user-agent: AlibabaCloud (Windows 10; amd64) Java/1.8.0_172-b11 tea-util/0.2.21 TeaDSL/1
accept: application/json

protected String doUrlRequest(String requestStr, Request request) throws Exception {

String response = null;
try {
Client client = createClient(accessKeyId,accessKeySecret,serverUrl);

RecognizeVehicleLicenseRequest recognizeVehicleLicenseRequest =
new RecognizeVehicleLicenseRequest();
if(StringUtils.isNotEmpty(request.getTpdParams().get(ServiceCallParamKeys.IMAGE))){
Base64.Decoder decoder = Base64.getDecoder();
byte[] imageByte = decoder.decode(request.getTpdParams().get(ServiceCallParamKeys.IMAGE).split(",")[1]);
InputStream stream = new ByteArrayInputStream(imageByte);
recognizeVehicleLicenseRequest.setBody(stream);
}
if(StringUtils.isNotEmpty(request.getTpdParams().get(ServiceCallParamKeys.IMAGE_URL))){
recognizeVehicleLicenseRequest.setUrl(request.getTpdParams().get(ServiceCallParamKeys.IMAGE_URL));
}
RuntimeOptions runtime = new RuntimeOptions();
RecognizeVehicleLicenseResponse recognizeVehicleLicenseResponse = client.recognizeVehicleLicenseWithOptions(recognizeVehicleLicenseRequest, runtime);
return JSONObject.toJSONString(recognizeVehicleLicenseResponse);
} catch (Exception e) {
log.error("调用阿里云-行驶证信息查询查询异常", e);
return e.getMessage();
}
}
/**

  • 使用AK&SK初始化账号Client
  • @param accessKeyId
  • @param accessKeySecret
  • @return Client
  • @throws Exception
    */
    private com.aliyun.ocr_api20210707.Client createClient(String accessKeyId, String accessKeySecret,String endpoint) throws Exception {
    com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
    // 必填,您的 AccessKey ID
    .setAccessKeyId(accessKeyId)
    // 必填,您的 AccessKey Secret
    .setAccessKeySecret(accessKeySecret);
    // Endpoint 请参考 https://api.aliyun.com/product/ocr-api
    // config.endpoint = "ocr-api.cn-hangzhou.aliyuncs.com";
    config.endpoint = endpoint;
    config.protocol="https";
    if(Constants.SWITCH_ON.equals(httpProxySwitch)){
    config.httpsProxy = "http://"+httpProxyHost+":"+httpProxyPort;
    }
    return new com.aliyun.ocr_api20210707.Client(config);
    }

展开
收起
三分钟热度的鱼 2023-12-13 19:41:52 89 0
2 条回答
写回答
取消 提交回答
  • 面对过去,不要迷离;面对未来,不必彷徨;活在今天,你只要把自己完全展示给别人看。

    根据您提供的代码和错误信息,问题可能出在阿里云OpenAPI的SDK代理设置上。请尝试以下解决方案:

    1. 确保您的httpProxySwitch变量设置为ON,并且httpProxyHosthttpProxyPort变量已经正确设置为您的代理服务器地址和端口。

    2. 检查您的网络连接是否正常,确保您可以访问阿里云OpenAPI的接口。

    3. 如果问题仍然存在,您可以尝试使用其他HTTP客户端库(如Apache HttpClient或OkHttp)替换阿里云OpenAPI的SDK,以排除SDK本身的问题。

    2023-12-14 21:58:17
    赞同 展开评论 打赏
  • 客户代码看着没问题,应该是https代理配置错了 可以让客户看下这篇文档

    http://tengine.taobao.org/document_cn/proxy_connect_cn.html 此回答整理自钉群“OpenAPI 开发者门户 - 值班服务群2群”

    2023-12-13 20:06:12
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
从 SDK 到编解码:视频直播架构解析 立即下载
跨平台的云服务SDK需要什么 立即下载
一个跨平台的云服务SDK需要什么 立即下载