Home  >  Article  >  Backend Development  >  file_get_content simulates post data in php

file_get_content simulates post data in php

WBOY
WBOYOriginal
2016-07-25 09:02:571222browse
  1. if($_POST['a'] && $_POST['b']) {
  2. echo 'post data success!';
  3. exit();
  4. }
  5. ?>
复制代码

文件2:indexx.php 主要测试文件。

  1. $url = 'http://www.test.com/index.php';
  2. $data = array(
  3. 'a' => '1',
  4. 'b' => '2WWW'
  5. );
  6. $params = array(
  7. 'http' => array(
  8. 'method' => 'POST',
  9. 'header' => "Content-type:application/x-www-form-urlencoded",
  10. 'content' => http_build_query($data),
  11. ));
  12. for($i=0;$i<3;$i++){
  13. $response = file_get_contents($url, false, stream_context_create($params));
  14. if ($response) {
  15. echo $response;
  16. break;
  17. } else {
  18. echo 'tring ' . $i . ' failed!
    ';
  19. }
  20. }
  21. ?>
复制代码

得到结果: post data success! 数据成功被Post。



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn