Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

142
Vistas
Guzzle not sending POST parameters

I am sending this as a test to a test webserver, but the response although its a 201 which means it got it, it does not show the posted data I want to send:

<?php
  $url = "https://jsonplaceholder.typicode.com/posts";
  $client = \Drupal::httpClient();

  $post_data = array('color' => 'red');
  $response = $client->request('POST', $url, [
    'form_params' => $post_data,
    'verify' => false
    ]);
  $body = $response->getBody();
  dsm($body);
?>

Is the format of the request I made incorrect?

I can see that it is not getting the post data because when I do a dsm of the response body, it isn't there.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

This worked for me, looks like I needed to add the headers:

$url="https://jsonplaceholder.typicode.com/posts";
    $client = \Drupal::httpClient();
    $post_data = $form_state->cleanValues()->getValues();
    $response = $client->request('POST', $url, [
    'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'],
    'form_params' => $post_data,
    'verify'=>false,
  ]);
    $body = $response->getBody()->getContents();
    $status = $response->getStatusCode();
    dsm($body);
    dsm($status);
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda