我正在我的WinJS通用应用程序中使用WordPress Rest API,并希望在让用户浏览产品之前以某种方式登录他们。我从API中获取产品。
我尝试了以下代码:
但是我得到了。
我还使用Postman尝试过,得到了这个结果。
我尝试了以下代码:
var settings = {
"async": true,
"crossDomain": true,
"url": "http://example.com/wp-json/users/me",
"method": "GET",
"headers": {
"authorization": "Basic dXNlcm5hbWU6cGFzc3dvcmQ==",
"cache-control": "no-cache"
}
}
$.ajax(settings).done(function(response) {
console.log(response);
});
但是我得到了。
DENIED - The requested resource requires user authentication. (XHR): GET - http://example.com/wp-json/users/me
我还使用Postman尝试过,得到了这个结果。
[{"code":"json_not_logged_in","message":"You are not currently logged in."}]
我不太确定我做错了什么,因为我正在尝试使用WordPress用户列表中的用户名/密码组合登录。
更新:
安装了一个基本身份验证插件之后,我现在能够让它工作了,但是当我输入错误的用户名或密码时,Windows 10会跳出自己的登录表单,而不是让我处理它。
现在我需要想办法抑制这种行为。