首页 > 后端开发 > php教程 > php获取http内容的函数示例

php获取http内容的函数示例

WBOY
发布: 2016-07-25 08:54:32
原创
927 人浏览过
  1. function http_open($url, $data, $cookie = null, $method = "GET", $timeout = 60) {

  2. $options = array();
  3. $options['http']['method'] = $method;
  4. $options['http']['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
  5. $options['http']['timeout'] = $timeout;
  6. if($method == "POST") :
  7. $length = strlen($data);
  8. $options['http']['header'] = "Content-type: application/x-www-form-urlencoded\r\n".
  9. "Content-Length: {$length}\r\n".
  10. "P3P: CP=\"CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR\"\r\n".
  11. "cookie: {$cookie}\r\n".
  12. "Connection: close\r\n";
  13. $options['http']['content'] = $data;
  14. else: // by bbs.it-home.org
  15. $options['http']['header'] = "Content-type: application/x-www-form-urlencoded\r\n".
  16. "P3P: CP=\"CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR\"\r\n".
  17. "cookie: {$cookie}\r\n".
  18. "Connection: close\r\n";
  19. endif;
  20. $context = stream_context_create($options);

  21. return file_get_contents($url, 0, $context);
  22. }
  23. echo http_open("http://localhost/1.php", "username=haowei", "id=5", "POST");
复制代码


来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板