I'm trying to send a basic AJAX request through browser console. The task demands an authorization so I've got a login and a secret key for the request. My code:
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);
the problem is that everytime I get the 401 error and a response from server:
Authorization header is incorrect. Correct header example:\r\nAuthorization: Mindbox secretKey=\"PUT_YOUR_SECRET_KEY_HERE\
Can anyone kindly help me here? I've tried hard to find some info about authorization headers but couldn't achieve anything valuable.
CodePudding user response:
You can set the header just like you did with Content-type
req.setRequestHeader('Authorization', 'Mindbox secretKey=\"PUT_YOUR_SECRET_KEY_HERE\"');