1
This commit is contained in:
@@ -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);
|
||||
|
||||
// 检查错误码
|
||||
|
||||
Reference in New Issue
Block a user