SASAOO

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 230|回复: 0

实现获取http内容的php函数

[复制链接]

25

主题

31

帖子

129

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
129
发表于 2019-7-16 13:59:15 | 显示全部楼层 |阅读模式
  1. <?php
  2. function http_open($url, $data, $cookie = null, $method = "GET", $timeout = 60) {
  3. $options = array();
  4. $options['http']['method'] = $method;
  5. $options['http']['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
  6. $options['http']['timeout'] = $timeout;
  7. if($method == "POST") :
  8. $length = strlen($data);
  9. //  www.jbxue.com
  10. $options['http']['header'] = "Content-type: application/x-www-form-urlencoded\r\n".
  11. "Content-Length: {$length}\r\n".
  12. "P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"\r\n".
  13. "cookie: {$cookie}\r\n".
  14. "Connection: close\r\n";
  15. $options['http']['content'] = $data;
  16. else:
  17. $options['http']['header'] = "Content-type: application/x-www-form-urlencoded\r\n".
  18. "P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"\r\n".
  19. "cookie: {$cookie}\r\n".
  20. "Connection: close\r\n";
  21. endif;

  22. $context = stream_context_create($options);
  23. return file_get_contents($url, 0, $context);
  24. }
  25. echo http_open("http://www.jbxue.com/1.php", "username=haowei", "id=5", "POST");
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|SASAOO.

GMT+8, 2019-9-18 09:19 , Processed in 0.078124 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表