我正在尝试为 jaredhendrickson13 / pfsense-api(https://github.com/jaredhendrickson13/pfsense-api)构建一个 web-gui,要么我无法获得返回的数组索引,要么它们不在那里。
我使用 laravel8 与 PHP 7.4
我的代码得到响应;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://192.168.1.175/api/v1/firewall/rule",
CURLOPT_TIMEOUT => 30000,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_SSL_VERIFYPEER => false, //add line
CURLOPT_SSL_VERIFYHOST => false, //add line
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_USERPWD => "$username:$password",
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
// Set Here Your Requesred Headers
'Content-Type: application/json',
),
));
$response = curl_exec($curl);
curl_close($curl);
$object = json_decode($response,true);
return $object;
和输出我 gettins 是;
{
"status": "ok",
"code": 200,
"return": 0,
"message": "Success",
"data": [
{
"id": "",
"tracker": "1665883545",
"type": "pass",
"intece": "wan",
"ipprotocol": "inet",
"tag": "",
"tagged": "",
"max": "",
"max-src-nodes": "",
"max-src-conn": "",
"max-src-states": "",
"statetimeout": "",
"statetype": "keep state",
"os": "",
"protocol": "tcp",
"source": {
"any": ""
},
"destination": {
"address": "192.168.1.201"
},
"descr": "Test2",
"created": {
"time": "1665883545",
"username": "admin@192.168.1.100 (Local Database)"
},
"updated": {
"time": "1665883556",
"username": "admin@192.168.1.100 (Local Database)"
}
},
{
"id": "",
"tracker": "1665883538",
"type": "pass",
"intece": "wan",
"ipprotocol": "inet",
"tag": "",
"tagged": "",
"max": "",
"max-src-nodes": "",
"max-src-conn": "",
"max-src-states": "",
"statetimeout": "",
"statetype": "keep state",
"os": "",
"protocol": "tcp",
"source": {
"any": ""
},
"destination": {
"address": "192.168.1.202"
},
"descr": "Test1",
"created": {
"time": "1665883538",
"username": "admin@192.168.1.100 (Local Database)"
},
"updated": {
"time": "1665883566",
"username": "admin@192.168.1.100 (Local Database)"
}
},
{
"type": "pass",
"ipprotocol": "inet",
"descr": "Default allow LAN to any rule",
"intece": "lan",
"tracker": "0100000101",
"source": {
"network": "lan"
},
"destination": {
"any": ""
}
},
{
"type": "pass",
"ipprotocol": "inet6",
"descr": "Default allow LAN IPv6 to any rule",
"intece": "lan",
"tracker": "0100000102",
"source": {
"network": "lan"
},
"destination": {
"any": ""
}
}
]
}
是邮递员的回应,与我的输出相同;
{
"status": "ok",
"code": 200,
"return": 0,
"message": "Success",
"data": [
{
"id": "",
"tracker": "1665883545",
"type": "pass",
"intece": "wan",
"ipprotocol": "inet",
"tag": "",
"tagged": "",
"max": "",
"max-src-nodes": "",
"max-src-conn": "",
"max-src-states": "",
"statetimeout": "",
"statetype": "keep state",
"os": "",
"protocol": "tcp",
"source": {
"any": ""
},
"destination": {
"address": "192.168.1.201"
},
"descr": "Test2",
"created": {
"time": "1665883545",
"username": "admin@192.168.1.100 (Local Database)"
},
"updated": {
"time": "1665883556",
"username": "admin@192.168.1.100 (Local Database)"
}
},
{
"id": "",
"tracker": "1665883538",
"type": "pass",
"intece": "wan",
"ipprotocol": "inet",
"tag": "",
"tagged": "",
"max": "",
"max-src-nodes": "",
"max-src-conn": "",
"max-src-states": "",
"statetimeout": "",
"statetype": "keep state",
"os": "",
"protocol": "tcp",
"source": {
"any": ""
},
"destination": {
"address": "192.168.1.202"
},
"descr": "Test1",
"created": {
"time": "1665883538",
"username": "admin@192.168.1.100 (Local Database)"
},
"updated": {
"time": "1665883566",
"username": "admin@192.168.1.100 (Local Database)"
}
},
{
"type": "pass",
"ipprotocol": "inet",
"descr": "Default allow LAN to any rule",
"intece": "lan",
"tracker": "0100000101",
"source": {
"network": "lan"
},
"destination": {
"any": ""
}
},
{
"type": "pass",
"ipprotocol": "inet6",
"descr": "Default allow LAN IPv6 to any rule",
"intece": "lan",
"tracker": "0100000102",
"source": {
"network": "lan"
},
"destination": {
"any": ""
}
}
]
}
如何提取“数据”部分放入 foreach 循环?
它看起来像响应有点坏了,但我不能决定我是否做错了。
谢谢
从原始 curl 更改为 Http 类工作。
本站系公益性非盈利分享网址,本文来自用户投稿,不代表边看边学立场,如若转载,请注明出处
评论列表(83条)