0

I built a very basic webAPI that when called prints some json data on the screen.

I'm calling the api with the following

function getEnvironmentList(){ $fullUrl = "localhost/serverList/api/rest.php?action=allenvironments&format=json"; $jsonDataRaw = file_get_contents($fullUrl); return $jsonDataRaw; } $jsonData = getEnvironmentList(); echo "<PRE>"; var_dump(json_decode($jsonData, true)); echo "</PRE>"; 

I get the error Warning: file_get_contents(localhost/serverList/api/rest.php?action=allenvironments&format=json): failed to open stream: No error in C:\path\inc\getJSONdata.php on line 6

Yet when I visit that URL I see this

{"1":{"environmentID":"1","envName":"UAT","envCreatedBy":"mhopkins","envCreatedDtTm":"2013-06-30 00:34:57","envUpdatedBy":"mhopkins","envUpdatedDtTm":"2013-06-30 00:34:57"},"3":{"environmentID":"3","envName":"Platinum","envCreatedBy":"mhopkins","envCreatedDtTm":"2013-06-30 00:37:38","envUpdatedBy":"phpsense","envUpdatedDtTm":"2013-06-30 00:37:38"}} 

I'm really confused why the code can't seem to realize there is json data there...

1 Answer 1

3

You forgot the http.

$fullUrl = "http://localhost/serverList/api/rest.php?action=allenvironments&format=json"; 
Sign up to request clarification or add additional context in comments.

2 Comments

yup, that would be it. I guess I just figured if I could copy/paste it and see data, the computer would too. PHP is finicky! Thanks!
countdown timer is on 11 minutes. I will once it hits 0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.