我正在嘗試通過瀏覽器控制臺發送一個基本的 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\
任何人都可以在這里幫助我嗎?我努力尋找有關授權標頭的一些資訊,但無法獲得任何有價值的資訊。
uj5u.com熱心網友回復:
您可以像設定標題一樣設定標題Content-type
req.setRequestHeader('Authorization', 'Mindbox secretKey=\"PUT_YOUR_SECRET_KEY_HERE\"');
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/485134.html
標籤:javascript json 阿贾克斯 授权
