加入收藏 | 设为首页 | 会员中心 | 我要投稿 北几岛 (https://www.beijidao.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

将curl响应保存到php变量中

发布时间:2021-08-28 05:09:08 所属栏目:大数据 来源: https://www.jb51.cc
导读:我试图从实例内部访问我的ec2的公共主机名. 我想运行这个命令 curl http:// 169 254.169.254/latest/Meta-data/public-hostname 在PHP脚本中并将响应保存到变量中.我怎样才能做到这一点? 解决方法: 你可以这样做 ?PHP //URL of targeted site $url = "http:

我试图从实例内部访问我的ec2的公共主机名.

我想运行这个命令

curl http:// 169 254.169.254/latest/Meta-data/public-hostname

在PHP脚本中并将响应保存到变量中.我怎样才能做到这一点?

解决方法:

你可以这样做

<?PHP  
//URL of targeted site  
$url = "http://www.yahoo.com/";  
$ch = curl_init();  

// set URL and other appropriate options  
curl_setopt($ch, CURLOPT_URL, $url);  
curl_setopt($ch, CURLOPT_HEADER, 0);  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  

// grab URL and pass it to the browser  

$output = curl_exec($ch);  

//echo $output;

// close curl resource, and free up system resources  
curl_close($ch);  
?>  

$output变量包含响应.

(编辑:北几岛)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读