You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Comodo合作伙伴门户API在Postman可认证,Google Apps Script失败求助

解决Google Apps Script调用Comodo合作伙伴API认证失败问题

问题分析

你遇到的核心问题是Google Apps Script(GAS)的UrlFetchAPI参数规范与浏览器fetch API不一致,导致请求参数未被Comodo服务器正确解析,返回E13000参数无效错误。以下是关键差异及修复方案:

关键错误点

  1. 请求体参数名错误:GAS中请求体对应的参数是payload,而非浏览器fetch中的body,你的代码使用body导致服务器未接收到用户名/密码。
  2. 重定向参数格式错误:GAS中重定向配置使用followRedirects(布尔值),而非redirect: 'follow'字符串。
  3. 缺少SSL证书忽略配置:对应curl的-k参数,GAS默认会验证SSL证书,可能因Comodo证书信任问题导致请求失败。

修复后的代码

function getAuthorizationBearerToken() {
  var url = "https://partner.cwatch.comodo.com/login";
  
  var headers = {
    'Cache-Control': 'no-cache',
    'Content-Type': 'application/json',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36'
  };

  var payload = JSON.stringify({
    "username": "myuser",
    "password": "mypass"
  });

  var options = {
    method: 'POST',
    headers: headers,
    payload: payload,
    followRedirects: true,
    muteHttpExceptions: true,
    validateHttpsCertificates: false // 对应curl的-k参数
  };

  var response = UrlFetchApp.fetch(url, options);
  Logger.log(response.getContentText());
}

额外说明

  • 添加User-Agent头是为了模拟浏览器请求,部分服务器会拦截无规范User-Agent的请求;
  • validateHttpsCertificates: false仅用于测试环境,生产环境建议确认证书有效性后移除该配置;
  • 确认用户名/密码无误的情况下,执行修改后的代码即可正常获取Bearer Token。

内容的提问来源于stack exchange,提问作者Francisco Cortes

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 00:54:53