Magento2: Web service Call POST method
-
12-01-2021 - |
Question
I wanted to call Web service using POST method and attache the Data values.
Here is my URL : http://api.geonames.org/citiesJSON which takes below data in POST.
north=44.1&south=-9.9&east=-22.4&west=55.2&lang=de&username=demo
How can I Form POST URL and Call POST Web service. Thanks in Advance.
Solution
I checked with above data but the credit usage exceeds for that user account, I tried with the new account it's working, please find the curl call below,
$ch = curl_init();
$url = "http://api.geonames.org/citiesJSON";
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, "north=44.1&south=-9.9&east=-22.4&west=55.2&lang=de&username=chez");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
print_r($data);
die();
If this answer helpful for you means, accept the answer
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange