How to Pass JSON Data in a URL using CURL in PHP ?

by cristobal , in category: Technology , 3 years ago

How to Pass JSON Data in a URL using CURL in PHP ?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by bailey_conroy , 3 years ago

Code to post JSON Data in a URL using CURL in PHP

1
2
3
4
5
6
7
8
9
$url='https://test.com/{your_segment}';
$jsonData='{"name":"Example",
"email":"example@test.com"
}';
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
curl_close($ch);