Skip to content

Instantly share code, notes, and snippets.

@flowerains
Created September 15, 2015 07:42
Show Gist options
  • Save flowerains/3a31df1816a80ee755f6 to your computer and use it in GitHub Desktop.
Save flowerains/3a31df1816a80ee755f6 to your computer and use it in GitHub Desktop.
一个PHP原生的发送POST请求的方法
<?php
$url = 'http://h.bilibili.com/api/pushS';
$data = array('act' => 'getHidInfo', 'key2' => 'value2');
// use key 'http' even if you send the request to https://...
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data),
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
var_dump($result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment