0

I've tried dozens of times to debug this, but I can't find where my error code. The problem is simple, I just want to post data with the application/json format

$this->client = new GuzzleHttp\Client(['base_uri' =>  'https://myendpointapi.com/']);
$headers =  [
    'Authorization' => $auth,
    'Accept'=>'application/json',
    'Content-Type' => $contentTypes
];
$url = "my-service";
$data = ["foo" => "bar"];
$this->client->send('POST',$url,["headers" => $headers, "json" => $data ]);

but the error I cant post $data, the response inform me no data send by me. I am also try to change $data value like

$data = array(["foo" => "bar"])

or change the format to multipart request (application/x-www-form-urlencoded) but the response keep same. I don't know why my code is not send the data.

halfer
  • 19,824
  • 17
  • 99
  • 186
ikbal maulana
  • 115
  • 1
  • 8
  • Does this answer your question? [How can I use Guzzle to send a POST request in JSON?](https://stackoverflow.com/questions/22244738/how-can-i-use-guzzle-to-send-a-post-request-in-json) – DaGhostman Dimitrov Apr 11 '20 at 16:48
  • Test your request with a service like https://postb.in/ so you can inspect what is been sent from the code. – Pablo Apr 12 '20 at 00:27

0 Answers0