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

206
Views
¿Cómo configurar el encabezado y las opciones en axios?

Uso Axios para realizar una publicación HTTP como esta:

 import axios from 'axios' params = {'HTTP_CONTENT_LANGUAGE': self.language} headers = {'header1': value} axios.post(url, params, headers)

¿Es esto correcto? O debería hacer:

 axios.post(url, params: params, headers: headers)
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Hay varias formas de hacer esto:

  • Para una sola solicitud:

     let config = { headers: { header1: value, } } let data = { 'HTTP_CONTENT_LANGUAGE': self.language } axios.post(URL, data, config).then(...)
  • Para establecer la configuración global predeterminada:

     axios.defaults.headers.post['header1'] = 'value' // for POST requests axios.defaults.headers.common['header1'] = 'value' // for all requests
  • Para configurar como predeterminado en la instancia de axios:

     let instance = axios.create({ headers: { post: { // can be common or any other method header1: 'value1' } } }) //- or after instance has been created instance.defaults.headers.post['header1'] = 'value' //- or before a request is made // using Interceptors instance.interceptors.request.use(config => { config.headers.post['header1'] = 'value'; return config; });
over 4 years ago · Santiago Trujillo Report

0

Puede enviar una solicitud de obtención con encabezados (para la autenticación con jwt, por ejemplo):

 axios.get('https://example.com/getSomething', { headers: { Authorization: 'Bearer ' + token //the token is a variable which holds the token } })

También puede enviar una solicitud de publicación.

 axios.post('https://example.com/postSomething', { email: varEmail, //varEmail is a variable which holds the email password: varPassword }, { headers: { Authorization: 'Bearer ' + varToken } })

Mi forma de hacerlo es establecer una solicitud como esta:

 axios({ method: 'post', //you can set what request you want to be url: 'https://example.com/request', data: {id: varID}, headers: { Authorization: 'Bearer ' + varToken } })
over 4 years ago · Santiago Trujillo Report

0

 axios.post('url', {"body":data}, { headers: { 'Content-Type': 'application/json' } } )

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!