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

799
Views
En Laravel, envíe una solicitud de publicación con datos de objetos json

Quiero enviar una solicitud con la fachada Http en Laravel, pero no puedo pasar los datos del objeto json, debe ser solo una matriz.

 Http::withHeaders(['Content-Type' => 'application/json'])->withOptions(['headers' => $coockie])->post($this->policy_url . $address, json_encode($data));

El valor de mi variable de datos:

 $data = [ "document" => [ "customerId" => 1, "currencyId" => 1, "settlementPolicyId" => 8, "storeId" => 16, "documentPatternId" => 2, "items" => [ [ "productId" => 193, "unitId" => 2, "quantity" => 1, "storeId" => 16, "TrackingFactor1" => "1214", "PartTrackingFactorRef1" => 1053, "TrackingFactorHasQuantity1" => true, "TrackingFactorValue" => "‏test", "fee" => 0 ] ] ], "payments" => [ [ "key" => "Cash", "amount" => 445810, "attr" => [] ] ] ];

El error:

 TypeError Argument 2 passed to Illuminate\Http\Client\PendingRequest::post() must be of the type array, string given
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Puede intentar usar el método withBody

 Http::withBody(json_encode($data), 'application/json') ->withOptions([ 'headers' => $coockie ]) ->post($this->policy_url . $address);
over 4 years ago · Santiago Trujillo Report

0

Haz json_encode($data) antes de enviarlo a la solicitud.

 $myArray = json_encode($data); $finalData = explode(' ',$myArray);
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!