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

143
Views
Guzzle no envía parámetros POST

Estoy enviando esto como una prueba a un servidor web de prueba, pero la respuesta, aunque es un 201, lo que significa que lo recibió, no muestra los datos publicados que quiero enviar:

 <?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); ?>

¿El formato de la solicitud que hice es incorrecto?

Puedo ver que no está recibiendo los datos de la publicación porque cuando hago un dsm del cuerpo de la respuesta, no está allí.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Esto funcionó para mí, parece que necesitaba agregar los encabezados:

 $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 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!