我正在尝试为我们的公司编写一个永恒的API,实现与外部系统的集成。例如,Woo Commerce向NetSuite发送订单。
我写了一个基本的休息回来
function doGet(requestParams) {
return "got";
}
我的测试html页面是这样写的
<script>
// Create a request variable and assign a new XMLHttpRequest object to it.
var request = new XMLHttpRequest();
request.open('GET', 'https://debugger.netsuite.com/app/site/hosting/restlet.nl?script=XXX&deploy=XXX ', true);
request.setRequestHeader("Content-Type", "application/json");
request.onload = function () {
// Begin accessing JSON data here
var data = JSON.parse(this.response);
if (request.status >= 200 && request.status < 400) {
console.log(data);
} else {
console.log('error');
}
}
// Send request
request.send();
</script>
我能得到的只是
跨源请求已阻止:同源策略禁止在https://debugger.netsuite.com/app/site/hosting/restlet.nl?script=XXX&deploy=XXX上读取远程资源。 (原因:CORS请求未成功)
如何让这个API工作
你不能直接这样做。没有本地Netsuite集成可以让您设置CORS标头。
您可以通过AWS lambda服务代理您的呼叫,这将非常高效且相当便宜