【问题标题】:Call Marketo API using javascript only仅使用 javascript 调用 Marketo API
【发布时间】:2016-07-29 23:27:14
【问题描述】:

我目前正在尝试从 Marketo 的 API 检索和发送数据。问题是:我的网络平台是 Salesforce Community。如果我正确理解了这个网络工具,除了纯 javascript,我不能使用任何其他东西。

我已经构建了一个这样的 CORS 请求:

function createCORSRequest(method, url) {
  var xhr = new XMLHttpRequest();

  if ("withCredentials" in xhr) {
    xhr.open(method, url, true);
  } else if (typeof XDomainRequest != "undefined") {
    xhr = new XDomainRequest();
    xhr.open(method, url);
  } else {
    xhr = null;
  }
  return xhr;
}

function makeCorsRequest() {
  var url = document.getElementById('url').value;
  var xhr = createCORSRequest('GET', url);
  if (!xhr) {
    alert('CORS not supported');
    return;
  }

  xhr.onload = function() {
    var text = xhr.responseText;
    alert('Response from CORS request to ' + url + 'is : ' + text);
  };

  xhr.onerror = function() {
    alert('Woops, there was an error making the request.');
  };

  xhr.send();
}

在http://www.html5rocks.com/en/tutorials/cors/ 的帮助下,但由于此错误再次出现,服务器似乎不接受请求:

“请求的资源上不存在'Access-Control-Allow-Origin'标头。因此不允许访问源'http://testurl...'。”

有人知道 Marketo 的 API 是否接受 CORS 请求吗?或者也许有一个想法可以帮助我解决这个问题?非常感谢。

【问题讨论】:

    标签: javascript api rest marketo salesforce-communities


    【解决方案1】:

    Marketo REST API 不允许 CORS 请求。在浏览器的客户端进行调用也存在安全风险,因为您将暴露您的访问令牌。根据您尝试执行的操作,可能会有其他选择,或者您可以设置一个简单的服务来代理您的请求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-06-29
      • 2018-02-06
      • 2012-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多