php模拟post

16 12 月

今天做个东西需要用到这个,顺便记录下。

使用方法:away_post(网址,数组);

<?php
/* awaysoft.com
tom
*/
function array_to_string($arrays){
$values = array();
foreach($arrays as $key=>$value)
$values[]= “$key=”.urlencode($value);

return implode(“&”, $values);
}

function away_post($url, $arrays){
$posts = array_to_string($arrays);
$context = array(
‘http’=>array(
‘method’ => ‘POST’,
‘header’ => “Content-type: application/x-www-form-urlencoded\r\n”.
“User-Agent: Away User synchronization Client\r\n”.
“Content-length: “.(strlen($posts)),
‘content’ => $posts
)
);
$stream_context = stream_context_create($context);
return file_get_contents($url, FALSE, $stream_context);
}:

 

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注