Question : php curl post json
Answered by : -1vajs8k9qntw
$ch = curl_init( $url );
# Setup request to send json via POST.
$payload = json_encode( array( "customer"=> $data ) );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
# Return response instead of printing.
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
# Send request.
$result = curl_exec($ch);
curl_close($ch);
Source : https://stackoverflow.com/questions/11079135/how-to-post-json-data-with-php-curl | Last Update : Mon, 12 Jul 21
Question : php curl_exec get response json
Answered by : homely-hamerkop-gx7uktp2z1jz
$result = curl_exec($cURL);
$result = json_decode($result,true);
Source : | Last Update : Thu, 08 Oct 20
Question : php curl post json
Answered by : martin-mladenov-2lnvs7ib3riv
function curl( string $url, array $data)
{ function send($url, $request) { $ch = curl_init(); $headers = [ 'Accept: application/json', 'Content-Type: application/json', ]; $options = [ CURLOPT_URL => $url, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $request, CURLOPT_FOLLOWLOCATION => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => true, CURLOPT_HTTPHEADER => $headers, ]; curl_setopt_array($ch, $options); $response = curl_exec($ch); curl_close($ch); return $response; } return send($url, json_encode($data));
}
Source : | Last Update : Tue, 05 Jul 22