赞
踩
使用curl选项 -u 可以完成HTTP或者FTP的认证,可以指定密码,也可以不指定密码在后续操作中输入密码:
curl -u admin:123456 http://192.168.140.128:6801/daemonstatus.json
使用php中curl请求上述链接时则为
- $url = "http://192.168.140.128:6801/daemonstatus.json";
- $arr_header[] = "Content-Type:application/json";
- $arr_header[] = "Authorization: Basic ".base64_encode("admin:123456"); //添加头,在name和pass处填写对应账号密码
-
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, 'http://'.$ip.':'.$port.'/daemonstatus.json' );
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- if(!empty($arr_header)){
- curl_setopt($ch, CURLOPT_HTTPHEADER, $arr_header);
- }
- $response = curl_exec($ch);
- curl_close($ch);
- return json_decode($response);
-
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。