我正在尝试访问需要基本身份验证凭据的 Adyen 测试 API。https://docs.adyen.com/developers/ecommerce-integration
但是当我尝试使用 XMLHttpRequest POST 请求访问 API 时,我得到了401 Unauthorized响应。
Javascript代码
var url = "https://pal-test.adyen.com/pal/servlet/Payment/v25/authorise";
var username = "ws@Company.CompanyName";
var password = "J}5fJ6+?e6&lh/Zb0>r5y2W5t";
var base64Credentials = btoa(username+":"+password);
var xhttp = new XMLHttpRequest();
xhttp.open("POST", url, true);
xhttp.setRequestHeader("content-type", "application/json");
xhttp.setRequestHeader("Authorization", "Basic " + base64Credentials);
var requestParams = XXXXXXXX;
xhttp.send(requestParams);
结果