How do I send a POST request with PHP?

前端 未结 13 1932
暗喜
暗喜 2020-11-21 05:40

Actually I want to read the contents that come after the search query, when it is done. The problem is that the URL only accepts POST methods, and it does not t

13条回答
  •  庸人自扰
    2020-11-21 05:45

    Here is using just one command without cURL. Super simple.

    echo file_get_contents('https://www.server.com', false, stream_context_create([
        'http' => [
            'method' => 'POST',
            'header'  => "Content-type: application/x-www-form-urlencoded",
            'content' => http_build_query([
                'key1' => 'Hello world!', 'key2' => 'second value'
            ])
        ]
    ]));
    

提交回复
热议问题