>  기사  >  백엔드 개발  >  php获取http内容的函数示例

php获取http内容的函数示例

WBOY
WBOY원래의
2016-07-25 08:54:32891검색
  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");
复制代码


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.