PHP analog Post send data

Source: Internet
Author: User
  1. <? Php
  2. $flag = 0;
  3. The data to post
  4. $ARGV = Array (
  5. ' var1 ' = ' abc ',
  6. ' var2 ' = ' How are you '?
  7. Constructing the Post string
  8. foreach ($argv as $key = = $value) {
  9. if ($flag!=0) {
  10. $params. = "&";
  11. $flag = 1;
  12. }
  13. $params. = $key. " ="; $params. = UrlEncode ($value);
  14. $flag = 1;
  15. }
  16. $length = strlen ($params);
  17. Create a socket connection
  18. $fp = Fsockopen ("127.0.0.1", $errno, $errstr, ten) or exit ($errstr. " ---> ". $errno);
  19. Constructs the header of a POST request
  20. $header = "post/mobile/try.php http/1.1";
  21. $header. = "host:127.0.0.1";
  22. $header. = "referer:/mobile/sendpost.php";
  23. $header. = "content-type:application/x-www-form-urlencoded";
  24. $header. = "Content-length:". $length. ";
  25. $header. = "Connection:close";
  26. Add a string for post
  27. $header. = $params. "";
  28. Send data for Post
  29. Fputs ($fp, $header);
  30. $inheader = 1;
  31. while (!feof ($fp)) {
  32. $line = fgets ($fp, 1024); Removal of the header of the request package shows only the return data of the page
  33. if ($inheader && ($line = = "N" | | $line = = "")) {
  34. $inheader = 0;
  35. }
  36. if ($inheader = = 0) {
  37. Echo $line;
  38. }
  39. }
  40. Fclose ($FP);
  41. ?>
Copy Code
PHP, Post
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.