Sample code for PHP analog post submission

Source: Internet
Author: User
Tags form post php form urlencode
  1. /**
  2. * PHP in the Curl analog post submission
  3. * by bbs.it-home.org
  4. */
  5. $url = ' http://website/a.php ';
  6. $fields = Array (
  7. ' UserName ' =>urlencode (' a '),
  8. ' PWD ' =>urlencode (' B '),
  9. ' Appreturn ' =>urlencode (' C '),
  10. ' Appsql ' =>urlencode (' d '),
  11. );
  12. $fields _string = Http_build_query ($fields);
  13. $ch = Curl_init ();
  14. curl_setopt ($ch, Curlopt_url, $url); Set the URL to collect
  15. curl_setopt ($ch, curlopt_post,1); Set form to post
  16. curl_setopt ($ch, Curlopt_postfields, $fields _string);//Set Post parameters
  17. curl_setopt ($ch, curlopt_returntransfer,1); Print it out with a string.
  18. $re = curl_exec ($ch);//(if Curlopt_returntransfer is not set to 1, the contents of the HTML document will be executed and fetched, such as: 1; otherwise the result will be returned, not executed)
  19. Print_r ($re);
  20. $info = Curl_getinfo ($ch);//Request Information
  21. Print_r ($info);
  22. $data = Array (' UserName ' = ' bar ');
  23. $data = Http_build_query ($data);
  24. $opts = Array (
  25. ' http ' = = Array (
  26. ' Method ' = ' POST ',
  27. ' Header ' = ' content-type:application/x-www-form-urlencoded\r\n '.
  28. "Content-length:". Strlen ($data). "\ r \ n",
  29. ' Content ' = $data
  30. ),
  31. );
  32. $context = Stream_context_create ($opts);
  33. $html = File_get_contents ($url, False, $context);
  34. Echo $html;
  35. Var_dump ($http _response_header);
Copy Code

>>> Read more: PHP implements the code for simulating get and post requests PHP using the socket, curl, file_get_contents method post data instance PHP $_get $_post parameter length limit PHP Curl in post with Get application instance code PHP Curl Post Simple example PHP Curl implementation Get,post and cookie Instance code PHP receive parameters and get POST original data method Php Curl Submit Get,post, A simple example of a cookie PHP $_get,$_post,$_request and $_server usage php batch processing post value method PHP form post parameter automatically add escape character problem solution PHP implementation post PHP Curl simulates post transfer data function PHP Curl analog POST Request example PHP Fsockopen analog post-commit code

  • 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.