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

用php的fsocket模拟get提交 模拟post提交表单

程序员文章站 2022-06-10 17:23:09
...
  1. //fsocket模拟post提交
  2. $purl = "http://www.baidu.com";
  3. print_r(parse_url($url));
  4. sock_post($purl, "parm=ping");
  5. //fsocket模拟get提交
  6. function sock_get($url, $query)
  7. {
  8. $info = parse_url($url);
  9. $fp = fsockopen($info["host"], 80, $errno, $errstr, 3);
  10. $head = "GET " . $info['path'] . "?" . $info["query"] . " HTTP/1.0rn";
  11. $head .= "Host: " . $info['host'] . "rn";
  12. $head .= "rn";
  13. $write = fputs($fp, $head);
  14. while (!feof($fp)) {
  15. $line = fread($fp, 4096);
  16. echo $line;
  17. }
  18. }
  19. sock_post($purl, "parm=ping");
  20. function sock_post($url, $query)
  21. {
  22. $info = parse_url($url);
  23. $fp = fsockopen($info["host"], 80, $errno, $errstr, 3);
  24. $head = "POST " . $info['path'] . "?" . $info["query"] . " HTTP/1.0rn";
  25. $head .= "Host: " . $info['host'] . "rn";
  26. $head .= "Referer: http://" . $info['host'] . $info['path'] . "rn";
  27. $head .= "Content-type: application/x-www-form-urlencodedrn";
  28. $head .= "Content-Length: " . strlen(trim($query)) . "rn";
  29. $head .= "rn";
  30. $head .= trim($query);
  31. $write = fputs($fp, $head);
  32. while (!feof($fp)) {
  33. $line = fread($fp, 4096);
  34. echo $line;
  35. }
  36. }
  37. ?>
复制代码

php, fsocket, post