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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.