Tag: False method nbsp Time tar address each RET JSON
PHP uses the Curl method, make sure that the curl extension is turned on. Portal: http://www.cnblogs.com/wgq123/p/7450667.html
/**curl Request Get method
*@ $url String to request the URL address
*@ $dara Array parameters to pass
*@ $timeout int timeout period
* @return JSON
/
functionCurlgetrequest ($url= ",$data=Array(),$timeout=5){ if($url= = ' | |$timeout<=0){ return false; } $param= ' '; if(!Empty($data)){ foreach($data as $k=$v){ $param.=$k. ' = '.$v.‘ & '; } $param=RTrim($param, ' & '); $url=$url.‘?‘.$param; } $con=Curl_init (); curl_setopt ($con, Curlopt_url,$url); curl_setopt ($con, Curlopt_header,false); curl_setopt ($con, Curlopt_returntransfer,true); curl_setopt ($con, curlopt_timeout, (int)$timeout); $output= Curl_exec ($con); Curl_close ($con); return $output;}
/**curl Request Post Method
*@ $url String to request the URL address
*@ $dara Array parameters to pass
*@ $timeout int timeout period
* @return JSON
/
functionCurlpostrequest ($url= ",$data=Array(),$timeout=5){
if($url= = ' | |Empty($data) ||$timeout<=0){
return false;
}
$param= ' ';
foreach($data as $k=$v){
$param.=$k. ' = '.$v.‘ & ';
}
$param=RTrim($param, ' & ');
$con=Curl_init ();
curl_setopt ($con, Curlopt_url,$url);
curl_setopt ($con, Curlopt_header,false);
curl_setopt ($con, Curlopt_postfields,$param);
curl_setopt ($con, Curlopt_post,true); curl_setopt ($con, Curlopt_returntransfer,true);
curl_setopt ($con, curlopt_timeout, (int)$timeout);
$output= Curl_exec ($con);
Curl_close ($con);
return $output;
}
$url = "http://127.0.0.1/request.php";
$timeout = 5;
$data = Array (' name ' = ' Zhang San ', ' password ' = ' 123 ');
$res 1 =curlgetrequest ($url, $data);
$res 2 =curlpostrequest ($url, $data);
echo $res 2;
PHP uses the Curl method get, POST request