Level 11
You might try sending this as json
$response = $client->post('url', [
'json' => $params,
]);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi everyone i want to send json format data usimg guzzle 6.3 but its not working..don't understand why? please suggest.
$reqParamArray = array();
$reqParamArray['ApplicationCode'] = $ApplicationCode;
$reqParamArray['ServiceCode'] = $ServiceCode;
$reqParamArray['FileReferenceNo'] = $FileReferenceNo;
$reqParamArray['ReceiptDate'] = $ReceiptDate;
$reqParamArray['Name'] = $Name;
$reqParamArray['MobileNo'] = $MobileNo;
$reqParamArray['RTSDueDate'] = $RTSDueDate;
$reqParamArray['DistrictCode'] = $DistrictCode;
$reqParamArray['LocationType'] = $LocationType;
$reqParamArray['LocationName'] = $LocationName;
$reqParamArray['SourceCode'] = $SourceCode;
$reqParamArray['LastStatusDescription'] = $LastStatusDescription;
$reqParamArray['LastAction'] = $LastAction;
$reqParamArray['LastActionBy'] = $LastActionBy;
$reqParamArray['LastActionDate'] = $LastActionDate;
$reqParamArray['Remarks_Eng'] = $Remarks_Eng;
$reqParamArray['Level'] = $Level;
$reqParamArray['FileWithUser'] = $FileWithUser;
$reqParamArray['DeptCode'] = $DeptCode;
$params[] = $reqParamArray;
$data = json_encode($params);
$client = new Client([
'headers' => ['Content-Type' => 'application/json']
]);
$response = $client->post('url',
['body' => $data]
);
$response = json_decode($response->getBody(), true);
Thanks @Yorki but i have to send json encoded data .for me this works as expected
$data = json_encode($params);
$client = new Client([
'headers' => ['Content-Type' => 'application/json']
]);
$response = $client->post('url',
['body' => $data]
);
$response = json_decode($response->getBody(), true);
Please or to participate in this conversation.