Jump to content

[b]How to retrieve the JSON response from a URL[/b]


naik.apoorv

Recommended Posts

I have to get the data from the url

 

https://test.httpapi.com/api/domains/available.json?auth-userid=0&auth-password=password&domain-name=domain&tlds=com&tlds=info&tlds=org&tlds=net&suggest-alternative=true

 

The above url returns a JSON response when proper parameters are used .

Can anyone suggest a portion of code that can handle this problem ??

 

also the above url can return an xml response if the url used is

 

https://test.httpapi.com/api/domains/available.xml?auth-userid=0&auth-password=password&domain-name=domain&tlds=com&tlds=info&tlds=org&tlds=net&suggest-alternative=true

 

also can any1 provide a way of handling this .

I m quite new to php and in need of help

Use file_get_contents to retrieve the JSON output and json_decode to decode it.

<?php
$json = file_get_contents('https://test.httpapi.com/api/domains/available.xml?auth-userid=0&auth-password=password&domain-name=domain&tlds=com&tlds=info&tlds=org&tlds=net&suggest-alternative=true');
$ary = json_decode($json,true);
echo '<pre>' . print_r($ary,true) . '</pre>'; //show what's in the resultant array
?>

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.