无法通过对 JS 的 AJAX 请求的授权
Can't pass authorization with AJAX request on JS
我正在尝试通过浏览器控制台发送基本 AJAX 请求。该任务需要授权,因此我获得了请求的登录名和密钥。
我的代码:
var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://api.mindbox.cloud/v3/operations/sync?endpointId=hh.ru&operation=get.user', true, 'login', 'secret key');
xhr.setRequestHeader('Content-type', 'application/json; charset=utf-8');
xhr.send();
console.log('status:', xhr.status, xhr.statusText);
console.log('xhr.response:', xhr.response);
问题是每次我收到 401 错误和来自服务器的响应:
Authorization header is incorrect. Correct header example:\r\nAuthorization: Mindbox secretKey=\"PUT_YOUR_SECRET_KEY_HERE\
有人可以帮我吗?我努力寻找有关授权的一些信息 headers 但无法获得任何有价值的信息。
您可以像设置 Content-type
一样设置 header
req.setRequestHeader('Authorization', 'Mindbox secretKey=\"PUT_YOUR_SECRET_KEY_HERE\"');
我正在尝试通过浏览器控制台发送基本 AJAX 请求。该任务需要授权,因此我获得了请求的登录名和密钥。 我的代码:
var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://api.mindbox.cloud/v3/operations/sync?endpointId=hh.ru&operation=get.user', true, 'login', 'secret key');
xhr.setRequestHeader('Content-type', 'application/json; charset=utf-8');
xhr.send();
console.log('status:', xhr.status, xhr.statusText);
console.log('xhr.response:', xhr.response);
问题是每次我收到 401 错误和来自服务器的响应:
Authorization header is incorrect. Correct header example:\r\nAuthorization: Mindbox secretKey=\"PUT_YOUR_SECRET_KEY_HERE\
有人可以帮我吗?我努力寻找有关授权的一些信息 headers 但无法获得任何有价值的信息。
您可以像设置 Content-type
req.setRequestHeader('Authorization', 'Mindbox secretKey=\"PUT_YOUR_SECRET_KEY_HERE\"');