Maison  >  Article  >  développement back-end  >  用php的fsocket模拟get提交 模拟post提交表单

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

WBOY
WBOYoriginal
2016-07-25 08:45:18907parcourir
  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


Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Article précédent:PHP实现zip压缩解压通用函数 Article suivant:php缩放图片代码