Maison  >  Article  >  développement back-end  >  php 中 file_get_content 模拟post数据

php 中 file_get_content 模拟post数据

WBOY
WBOYoriginal
2016-07-25 09:02:571176parcourir
  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 $response = file_get_contents($url, false, stream_context_create($params));
  13. if ($response) {
  14. echo $response;
  15. break;
  16. } else {
  17. echo 'tring ' . $i . ' failed!
    ';
  18. }
  19. }
  20. ?>
复制代码

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



Déclaration:
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