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

WBOY
Libérer: 2016-07-25 08:45:18
original
913 Les gens l'ont consulté
  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


source:php.cn
Déclaration de ce site Web
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
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!