************************GET请求**********************
public function geteflist($name)
{
$url="http://localhost:1418/xxx/GetList";
$params=array('name'=>$name);
$result=do_get($url,$params);
echo json_encode($result);
return;
}
function do_get($url, $params) {
$url = "{$url}?" . http_build_query ( $params );
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_CUSTOMREQUEST, 'GET' );
curl_setopt ( $ch, CURLOPT_TIMEOUT, 60 );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $params );
$result = curl_exec ( $ch );
curl_close ( $ch );
return $result;
}
************************POST请求**********************
public function geteflist($name) { $url=http://localhost:1418/xxx/GetList; $params=array('areaName'=>$name); $headers=array( "Content-Type:application/json;charset=utf-8", "Accept:application/json;charset=utf-8" ); //json序列化 $params=json_encode($params, JSON_FORCE_OBJECT); $result=$this->do_post($url,$params,$headers); echo json_encode($result); return; } function do_post($url, $params, $headers) { $ch = curl_init (); curl_setopt ( $ch, CURLOPT_URL, $url ); curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt ( $ch, CURLOPT_CUSTOMREQUEST, 'POST' ); curl_setopt ( $ch, CURLOPT_POSTFIELDS, $params ); curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers ); curl_setopt ( $ch, CURLOPT_TIMEOUT, 60 ); $result = curl_exec ( $ch ); curl_close ( $ch ); return $result; }