<?php /** * 發送post請求 * @param string $url 請求地址 * @param array $post_data post鍵值對數據 * @return string */ function send_post($url, $post_data) { $postdata = http_build_query($post_data); $options = array( 'http' => array( 'method' => 'POST', 'header' => 'Content-type:application/x-www-form-urlencoded', 'content' => $postdata, 'timeout' => 15 * 60 // 超時時間(單位:s) ) ); $context = stream_context_create($options); $result = file_get_contents($url, false, $context); return $result; } //測試 /*$post_data = array( 'username' => 'makalo', 'password' => 'makelochen' ); echo send_post('http://localhost:8080/test.php', $post_data);*/ ?>