php get url content,PHP的通过CURL或file_get_contents请求第三方URL

CURL:

//访问网页数据

public

function get_web_content($url, $curl_data)

{

$options = array(

CURLOPT_RETURNTRANSFER => true, // return web page

CURLOPT_HEADER => false, // don't return headers

CURLOPT_FOLLOWLOCATION => true, // follow redirects

CURLOPT_ENCODING => "", // handle all encodings

CURLOPT_USERAGENT => "institution", // who am i

CURLOPT_AUTOREFERER => true, // set referer on redirect

CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect

CURLOPT_TIMEOUT => 120, // timeout on response

CURLOPT_MAXREDIRS => 10, // stop after 10 redirects

CURLOPT_POST => 1, // i am sending post data

CURLOPT_POSTFIELDS => $curl_data, // this are my post vars

CURLOPT_SSL_VERIFYHOST => 0, // don't verify ssl

CURLOPT_SSL_VERIFYPEER => false, //

CURLOPT_VERBOSE => 1 //

);

$ch = curl_init($url);

curl_setopt_array($ch, $options);

curl_setopt($ch, CURLOPT_HTTPHEADER, array("Expect:"));

$content = curl_exec($ch);

curl_close($ch);

return $content;

}

file_get_contents(get方式,拼接参数)

// 如:QQ校验成功,获取QQ用户信息

$res = file_get_contents("https://graph.qq.com/user/get_user_info?access_token=" . $access_token . "&oauth_consumer_key=" . $app_id . "&openid=" . $openid);

$res = json_decode($res, true); // 解码json并转数组

标签:ch,return,get,URL,file,curl,true,CURLOPT

来源: https://blog.csdn.net/qq_41912505/article/details/104748633

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值