Advertisement
zero50x

Отправить POST-запрос из скрипта без формы

Jun 1st, 2016
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.76 KB | None | 0 0
  1. // Создать контекст и инициализировать POST запрос
  2.     $context = stream_context_create(array(
  3.         'http' => array(
  4.             'method' => 'POST',
  5.             'header' => 'Content-Type: application/x-www-form-urlencoded' . PHP_EOL,
  6.             'content' => 'QUERY',
  7.         ),
  8.     ));
  9.  
  10. // Отправить запрос на себя, чтобы запустить тесты
  11.     echo file_get_contents(
  12.         $file = "http://site.ru/post2.php", //этот скрипт должен ловить POST-запрос
  13.         $use_include_path = false,
  14.         $context
  15.         );
  16.  
  17. /* Так в скрипт придёт один элемент с именем QUERY
  18. array(1) {
  19.   ["QUERY"]=>
  20.   string(0) ""
  21. }
  22. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement