PHP |如何发帖请求机构?

时间:2018-03-10 00:31:26

标签: php post

如何使用下一个查询发布请求?

请求正文:

_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);

1 个答案:

答案 0 :(得分:0)

有关详细信息,请查看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);

同时检查How to post data in PHP using file_get_contents?