欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

fsockopen访问网址

程序员文章站 2022-04-23 12:25:02
...
学习自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. }
复制代码
相关标签: fsockopen访问网址