I'm trying to send a POST request that contains a JSON string with the following headline: Content-Type: application/json.
From looking at the documents, I see that I can do something like this ...
$data = ['x' => 1, 'y' => 2, 'z' => 3];
$client = new \GuzzleHttp\Client($guzzleConfig);
$options = [
'json' => $data,
];
$client->post('http://example.com', $options);
My problem is that when I get to this point, $datathere was already json_encode'd.
I tried the following, but it does not work.
$data = json_encode(['x' => 1, 'y' => 2, 'z' => 3]);
$client = new \GuzzleHttp\Client($guzzleConfig);
$options = [
'body' => $data,
'headers' => ['Content-Type' => 'application/json'],
];
$client->post('http://example.com', $options);
My question is: can I use a parameter jsonwith an already encoded array? Or is there a way for me to just set the title Content-Type?
source
share