下面的两种方法,$url是链接,$data是传入参数(格式:"meta_one=1&meta_two=2")。
curl方法:
function do_post($url, $data) {
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt ( $ch, CURLOPT_POST, TRUE );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$ret = curl_exec ( $ch );
curl_close ( $ch );
return $ret;
}
file_get_contents方法:
function do_post2($url, $data) {
$options = array(
'http' => array(
'method' => 'POST',
'content' => $data
),
);
$result = file_get_contents($url, false, stream_context_create($options));
return $result;
}