利用curl給你介面傳遞參數 為什麼一直是空的 代碼如下:
$userAccounts = $_POST['userAccounts']; $userPassword = md5($_POST['userPassword']); if($userAccounts == "" || $userPassword == "") { echo "請將資料填寫完整"; }else { $url = 'http://192.168.1.135:9999/MJS/user/userRegisterSign'; $data = array( 'userAccounts' => $userAccounts, 'userPassword' => $userPassword ); $json_data = postData($url, $data); } function postData($url, $data) { $ch = curl_init(); $timeout = 300; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $handles = curl_exec($ch); curl_close($ch); /* return $handles;*/ }
回複內容:
利用curl給你介面傳遞參數 為什麼一直是空的 代碼如下:
$userAccounts = $_POST['userAccounts']; $userPassword = md5($_POST['userPassword']); if($userAccounts == "" || $userPassword == "") { echo "請將資料填寫完整"; }else { $url = 'http://192.168.1.135:9999/MJS/user/userRegisterSign'; $data = array( 'userAccounts' => $userAccounts, 'userPassword' => $userPassword ); $json_data = postData($url, $data); } function postData($url, $data) { $ch = curl_init(); $timeout = 300; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $handles = curl_exec($ch); curl_close($ch); /* return $handles;*/ }
http_build_query($data)