/** * 模拟post进行url请求 * @param string $url * @param json $post_data */ public function request_post($url = '',$ispost=true, $post_data) { if (empty($url) || empty($post_data)) { return false; } header("Content-type: text/html; charset=utf-8"); $ch = curl_init($url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($post_data)) ); $result = curl_exec($ch); return $result; }
传递的$post_data 要通过json_decode传化为json格式,$url传递java的接口地址