V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
9fan
V2EX  ›  程序员

钉钉服务端 api 设置代理

  •  
  •   9fan · 8 天前 · 534 次点击
    public static com.aliyun.dingtalkstorage_1_0.models.GetFileUploadInfoResponseBody getFileUploadInfo() {
    GetFileUploadInfoResponse rsp;
    try {
    RuntimeOptions runtimeOptions = new RuntimeOptions();
    // 设置代理
    // String url = "http://192.168.0.15:9028/api";
    // runtimeOptions.setHttpProxy(url);
    rsp = storageClient1.getFileUploadInfoWithOptions(
    getSpaceId(),
    new GetFileUploadInfoRequest()
    .setUnionId(getUser(null).getUnionid())
    .setProtocol("HEADER_SIGNATURE")
    .setMultipart(false),
    new GetFileUploadInfoHeaders().setXAcsDingtalkAccessToken(getAccessToken()),
    runtimeOptions
    );
    } catch (Exception e) {
    log.error("钉盘-获取文件上传信息 异常: ", e);
    throw new ServiceException("钉盘-获取文件上传信息 异常: " + e.getMessage());
    }
    com.aliyun.dingtalkstorage_1_0.models.GetFileUploadInfoResponseBody fileInfo = rsp.getBody();
    return fileInfo;
    } 这里一设置代理就错误:com.aliyun.tea.TeaUnretryableException: Unexpected response code for CONNECT: 400
    at com.aliyun.teaopenapi.Client.execute(Client.java:1183) 其中 192.168.0.15 中的 nginx 配置:server{
    listen 9028;
    server_name localhost;
    location /api {
    proxy_pass https://api.dingtalk.com/;
    proxy_connect_timeout 60;
    proxy_read_timeout 60;
    proxy_send_timeout 60;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host 'api.dingtalk.com';
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto https;
    }
    location / {
    proxy_pass https://oapi.dingtalk.com/;
    proxy_connect_timeout 60;
    proxy_read_timeout 60;
    proxy_send_timeout 60;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host 'oapi.dingtalk.com';
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto https;
    }
    } 下面是 nginx access.log -->> 192.168.0.69 - - [19/Dec/2024:10:24:15 +0800] "CONNECT api.dingtalk.com:443 HTTP/1.1" 400 157 "-" "-" 现在是想知道怎么在 RuntimeOptions 这里面设置正确的代理,官方文档翻了又翻,确实没有相关介绍,求助各位大佬给予帮助,立正感谢
    3 条回复
    rekulas
        1
    rekulas  
       7 天前
    没试过,要不考虑自己加个反代代理层,就不用管钉钉怎么实现了,http 协议都可以挂上
    yulgang
        2
    yulgang  
       7 天前
    日志里看 HTTP/1.1 400 感觉.....
     
    location /api {
    proxy_pass https://api.dingtalk.com;
    proxy_http_version 1.1; # 新加的
    proxy_connect_timeout 60;
    proxy_read_timeout 60;
    proxy_send_timeout 60;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host 'api.dingtalk.com';
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto https;
    proxy_set_header Connection ""; # 新加的
    }
     
    或者
     
    location /api {
    proxy_pass https://api.dingtalk.com;
    proxy_http_version 1.1; # 新加的
    proxy_set_header Upgrade $http_upgrade; # 新加的
    proxy_set_header Connection "upgrade"; # 新加的
    proxy_connect_timeout 60;
    proxy_read_timeout 60;
    proxy_send_timeout 60;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host 'api.dingtalk.com';
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto https;
    }
     
    感觉下面这个能行。
    9fan
        3
    9fan  
    OP
       3 天前
    感谢,已经把有关调用钉钉服务拆分了,直接放在有外网的机子上,直接远程调用,不代理了,已经给钉钉提工单了,没用
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5308 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 21ms · UTC 05:49 · PVG 13:49 · LAX 21:49 · JFK 00:49
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.