钉钉服务端 api 设置代理

6 小时 25 分钟前
 9fan
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 这里面设置正确的代理,官方文档翻了又翻,确实没有相关介绍,求助各位大佬给予帮助,立正感谢
280 次点击
所在节点    程序员
2 条回复
rekulas
2 小时 18 分钟前
没试过,要不考虑自己加个反代代理层,就不用管钉钉怎么实现了,http 协议都可以挂上
yulgang
2 小时 3 分钟前
日志里看 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;
}
 
感觉下面这个能行。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1098713

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX