$params是数组, 返回的$res为json
static function H_post($url, $params) { $params = json_encode($params); $ch = curl_init (); curl_setopt ( $ch, CURLOPT_URL, $url ); curl_setopt ( $ch, CURLOPT_POST, 1 ); curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, false ); // 不验证证书 curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, false ); // 不验证HOST curl_setopt ( $ch, CURLOPT_SSLVERSION, 1 ); curl_setopt ( $ch, CURLOPT_POSTFIELDS, $params ); curl_setopt ( $ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json; charset=utf-8', 'Content-Length: ' . strlen($params) ) ); curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true ); $res = curl_exec ( $ch ); curl_close ($ch); return $res; }
还没有评论,来说两句吧...