“Axios obtiene solicitud con el cuerpo” Código de respuesta

Solicitud de publicación de AXIOS API

import qs from 'qs';
const data = { 'bar': 123 };
const options = {
  method: 'POST',
  headers: { 'content-type': 'application/x-www-form-urlencoded' },
  data: qs.stringify(data),
  url,
};
axios(options);
Amused Ant

Axios obtiene solicitud con el cuerpo

/**
 * Package that needed:
 * 'qs', 'axios' 
 * install by `npm install qs --save 
 */

// You can Add more to this 
let headers = {
	'content-type': 'application/x-www-form-urlencoded',
};

let body = {
    field1: 'foo',
    field2: 'bar',
};

// For async_await
let reponse = await axios({
	method: 'POST',
    headers: headers,
    data: qs.stringify(body), // <---- This step it is important
    url: `${YOUR_URL}`,
}); 


return response['data'];
Johnmelodyme

Axios consigue cuerpo

  // `data` is the data to be sent as the request body
  // Only applicable for request methods 'PUT', 'POST', 'DELETE', and 'PATCH'
  // When no `transformRequest` is set, must be of one of the following types:
  // - string, plain object, ArrayBuffer, ArrayBufferView, URLSearchParams
  // - Browser only: FormData, File, Blob
  // - Node only: Stream, Buffer
  data: {
    firstName: 'Fred'
  },
Sanz Imagery

Respuestas similares a “Axios obtiene solicitud con el cuerpo”

Preguntas similares a “Axios obtiene solicitud con el cuerpo”

Más respuestas relacionadas con “Axios obtiene solicitud con el cuerpo” en JavaScript

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código