file_get_content simulates post data in php

WBOY
Release: 2016-07-25 09:02:57
Original
1217 people have browsed it
  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。



source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!