This commit is contained in:
2025-11-05 23:50:38 +08:00
parent 23c0375c55
commit e634f96887

View File

@@ -168,10 +168,16 @@ public class TencentDocApiUtil {
*/
public static JSONObject callApi(String accessToken, String apiUrl, String method, String body) {
try {
log.info("调用腾讯文档API: url={}, method={}", apiUrl, method);
URL url = new URL(apiUrl);
// 使用Proxy.NO_PROXY确保不使用系统代理直接连接到腾讯文档API
java.net.Proxy proxy = java.net.Proxy.NO_PROXY;
HttpURLConnection conn = (HttpURLConnection) url.openConnection(proxy);
// 禁用系统代理设置(双重保险)
System.setProperty("java.net.useSystemProxies", "false");
conn.setRequestMethod(method);
conn.setRequestProperty("Authorization", "Bearer " + accessToken);
conn.setRequestProperty("Content-Type", "application/json");
@@ -192,6 +198,8 @@ public class TencentDocApiUtil {
// 读取响应
int statusCode = conn.getResponseCode();
log.info("腾讯文档API响应状态码: {}", statusCode);
BufferedReader reader;
if (statusCode >= 200 && statusCode < 300) {
reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8));
@@ -207,8 +215,19 @@ public class TencentDocApiUtil {
reader.close();
String responseStr = response.toString();
log.debug("腾讯文档API响应: statusCode={}, response={}", statusCode, responseStr);
log.info("腾讯文档API响应: statusCode={}, responseLength={}, responsePreview={}",
statusCode, responseStr.length(),
responseStr.length() > 200 ? responseStr.substring(0, 200) + "..." : responseStr);
// 检查响应是否被代理拦截返回HTML说明被拦截了
if (responseStr.trim().startsWith("<html") || responseStr.trim().startsWith("<!DOCTYPE")) {
log.error("响应被代理拦截返回了HTML页面而不是JSON。响应内容: {}",
responseStr.length() > 500 ? responseStr.substring(0, 500) + "..." : responseStr);
throw new RuntimeException("请求被代理拦截返回了HTML页面。请检查系统代理设置或网络配置。响应: " +
(responseStr.length() > 200 ? responseStr.substring(0, 200) : responseStr));
}
// 尝试解析JSON
JSONObject result = JSON.parseObject(responseStr);
// 检查错误码