Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

184
Views
Cómo agregar autorización a la solicitud POST de node.js

Estoy configurando la solicitud POST

 var request = { host: endpoint, method: 'POST', path: '/_bulk', body: body, headers: { 'Content-Type': 'application/json', 'Host': endpoint, 'Content-Length': Buffer.byteLength(body), 'X-Amz-Security-Token': process.env.AWS_SESSION_TOKEN, 'X-Amz-Date': datetime, } };

Necesito agregar Autorización con nombre de usuario y contraseña, ¿cuál es la forma correcta y la sintaxis para hacerlo?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Para esto, puede usar la clave de autenticación o puede crear un token básico a partir del nombre de usuario y la contraseña, y pasar ese token en el encabezado.

 const username = 'username'; const password = 'password'; var request = { host: endpoint, method: 'POST', path: '/_bulk', body: body, headers: { 'Content-Type': 'application/json', 'Host': endpoint, 'Content-Length': Buffer.byteLength(body), 'X-Amz-Security-Token': process.env.AWS_SESSION_TOKEN, 'X-Amz-Date': datetime, }, auth: { 'username': username, 'password': password } };

O puede crear un token básico a partir del nombre de usuario y la contraseña. Y coloque ese token en el encabezado contra la clave de Autorización.

 const username = 'username'; const password = 'password'; const encodedBase64Token = Buffer.from(`${username}:${password}`).toString('base64'); const authorization = `Basic ${encodedBase64Token}`; var request = { host: endpoint, method: 'POST', path: '/_bulk', body: body, headers: { 'Content-Type': 'application/json', 'Host': endpoint, 'Content-Length': Buffer.byteLength(body), 'X-Amz-Security-Token': process.env.AWS_SESSION_TOKEN, 'X-Amz-Date': datetime, 'Authorization': authorization, } };
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!