跳至
[1]
[全屏预览]
/**
* file_get_contents 函数
* @param string $url @要访问的URL
* @param array $post_data @请求的数据(数组)
* @param string $method @请求方式 默认 post
* @return bool|string
*/
function file_contents_post($url = '', $post_data = array(), $method = 'POST')
{
$sFile = false;
if(!empty($post_data) && !empty($url)){
$data = http_build_query($post_data);
$opts = array(
'http'=>array(
'method' => $method,
'header' => "Content-type: application/x-www-form-urlencoded\r\n".
"Content-length: ".strlen($data)."\r\n" .
"Cookie: foo=bar\r\n" .
"\r\n",
'content' => $data
)
);
$cxContext = stream_context_create($opts);
$sFile = file_get_contents($url, false, $cxContext);
}
return $sFile;
}
Copy after login