0

How do I POST the request with the next query?

Request Body:

_username=test%40test.com&_password=1234&_remember_me=true

PHP:

$opts = array('http'=>
array(
'proxy'=>"",
'method'=>"POST",
'header'=>"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:51.0) Gecko/20100101 Firefox/51.0"
));

$context  = stream_context_create($opts);
$result = file_get_contents('https://website.com/login_check', false, $context);
sensen
  • 1

1 Answers1

0

For more details check docs

$opts = array(
    'http'=>
        array(
          'proxy' => "",
          'method' => "POST",
          'content' => '_username=test%40test.com&_password=1234&_remember_me=true',
          'header' => "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:51.0) Gecko/20100101 Firefox/51.0"
        )
);

$context  = stream_context_create($opts);
$result = file_get_contents('https://website.com/login_check', false, $context);

Also check How to post data in PHP using file_get_contents?

iwex
  • 384
  • 3
  • 17
  • Thank you, i get Parse error: syntax error, unexpected ''header'' (T_CONSTANT_ENCAPSED_STRING), expecting ')' in line 9. something wrong? – sensen Mar 10 '18 at 00:54
  • @sensen, sorry, i forgot comma after `content`. Updated – iwex Mar 10 '18 at 00:56