【问题标题】:PHP | How to POST Request Body?PHP |如何发布请求正文?
【发布时间】:2018-08-18 15:16:50
【问题描述】:

如何在下一个查询中发布请求?

请求正文:

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

【问题讨论】:

    标签: php post


    【解决方案1】:

    更多详情请查看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?

    【讨论】:

    • 谢谢,我收到 Parse error: syntax error, unexpected ''header'' (T_CONSTANT_ENCAPSED_STRING), expecting ')' in line 9. 有什么问题吗?
    • @sensen,对不起,我忘记了content 后面的逗号。更新
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-10
    • 2020-12-13
    • 1970-01-01
    • 1970-01-01
    • 2021-06-07
    • 2021-07-22
    相关资源
    最近更新 更多