fsockopen访问网址

WBOY
发布: 2016-07-25 08:49:21
原创
1182 人浏览过
学习自alipay
  1. function gateway($url, $time_out="60") {
  2. $urlinfo = parse_url($url);
  3. $errno = "";
  4. $errstr = "";
  5. $transports = "";
  6. if ($urlinfo['scheme'] == "https") {
  7. $transports = "ssl://";
  8. $urlinfo['port'] = "443";
  9. }else{
  10. $transports = "tcp://";
  11. $urlinfo['port'] = "80";
  12. }
  13. $fp = @fsockopen($transports.$urlinfo['host'], $urlinfo['port'], $errno, $errstr, $time_out);
  14. if (!$fp) {
  15. die("ERROR: $errno - $errstr
    \n");
  16. }else{
  17. fputs($fp, "POST ".$urlinfo['path']." HTTP/1.1\r\n");
  18. fputs($fp, "Host: ".$urlinfo['host']."\r\n");
  19. fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
  20. fputs($fp, "Content-length: ".strlen($urlinfo['query'])."\r\n");
  21. fputs($fp, "Connection: close\r\n\r\n");
  22. fputs($fp, $urlinfo['query']."\r\n\r\n");
  23. while(!feof($fp)) {
  24. $info[]=@fgets($fp, 1024);
  25. }
  26. fclose($fp);
  27. $info = implode(",", $info);
  28. var_dump($info);
  29. }
  30. }
复制代码


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