0

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.

2

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

1
  • This is perfect for core PHP. – kunj May 28 '18 at 7:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.