有没有办法从URL获取JSON并在PHP中使用它?

时间:2019-10-15 12:03:50

标签: php json rest api javascript-objects

我正在尝试从JSON请求中获取数据。我目前正在使用此代码:

<?php
$url='http://localhost:8080/rest/api/2/user?username=username';
$jiraUsers = file_get_contents($url);
$testUsers = json_decode($jiraUsers);
echo $testUsers[0];

This is what I want to echo and eventually change

我没有得到任何错误,但是得到了警告,没有别的:

警告:file_get_contents(http://localhost:8080/rest/api/2/user?username=username):打开流失败:HTTP请求失败!

我想念什么?还是file_get_contents不是首先获取数据的正确方法,我必须使用类似cURL的东西(更复杂吗?)?

0 个答案:

没有答案