【发布时间】:2016-10-05 10:13:55
【问题描述】:
我正在尝试使用基于 HTTPS 的基本身份验证通过 jQuery 从同源 (localhost) 调用 WooCommerce API。服务器是 Windows 上的 XAMPP。我正在使用自签名证书(CN=localhost)。当我访问网站的其余部分时,证书不会发出任何警告。我尝试将证书添加为受信任的根证书颁发机构。我什至允许 chrome://flags/#allow-insecure-localhost (即使证书有效)。我不断收到“401 Unauthorized”。
var username = "ck_????????????????????????????????????????";
var password = "cs_????????????????????????????????????????";
var up = username + ":" + password;
var authHeader = "Basic " + btoa(username + ":" + password);
WooClient.prototype.getProducts = function () {
return $.ajax({
url: "/myshop/wp-json/wc/v1/products",
type: "get",
dataType: "json",
xhrFields: {
withCredentials: true
},
beforeSend: function (xhr) {
xhr.setRequestHeader("Authorization", authHeader);
return true;
}
}).then(function (data) {
return data;
});
};
使用 Advanced Rest Client 执行的相同请求返回“200 OK”并在正文中返回所需的结果。
【问题讨论】:
-
嗯,我刚刚注意到使用 Edge 一切都很好。
标签: jquery wordpress ssl woocommerce