本文目录一览:
php curl get 参数
$cu = curl_init();
curl_setopt($cu, CURLOPT_URL, $url);
curl_setopt($cu, CURLOPT_RETURNTRANSFER, 1);
$ret = curl_exec($cu);
curl_close($cu);
其中$url变量可以是完整的URL+参数
php 使用curl函数并附带参数传递,接收返回的数据并保存在变量中
$Data = array('user' = 'xiaoming');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,'');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $Data);
$a = curl_exec($ch);
curl_close($ch);
print_r( $a );
php curl连接怎么加参数进去
function useCURL_Post( $url, $post_param = Array(), $TimeOUT = 45, $DataType = '' )
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL , $url );
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER , FALSE );
curl_setopt($curl, CURLOPT_ENCODING , "" );
curl_setopt($curl, CURLOPT_FOLLOWLOCATION , 1 );
curl_setopt($curl, CURLOPT_AUTOREFERER , 1 );
curl_setopt($curl, CURLOPT_POST , TRUE );
curl_setopt($curl, CURLOPT_POSTFIELDS , $post_param );
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT , $TimeOUT );
curl_setopt($curl, CURLOPT_TIMEOUT , $TimeOUT );
curl_setopt($curl, CURLOPT_RETURNTRANSFER , 1 );
if( $DataType == 'json' )
{
curl_setopt($curl, CURLOPT_HTTPHEADER, Array( 'Content-Type: application/json', 'Content-Length: ' . strlen( $post_param ) ) );
}
else
{
curl_setopt($curl, CURLOPT_HEADER, 0);
}
$data['content'] = curl_exec($curl);
$data['error'] = curl_error($curl);
$data['info'] = curl_getinfo($curl);
curl_close($curl);
return $data;
}
function useCURL_Get( $url, $TimeOUT = 45, $Headers = Array() )
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL , $url );
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER , FALSE );
curl_setopt($curl, CURLOPT_ENCODING , "" );
curl_setopt($curl, CURLOPT_FOLLOWLOCATION , 1 );
curl_setopt($curl, CURLOPT_AUTOREFERER , 1 );
curl_setopt($curl, CURLOPT_HTTPGET , 1 );
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT , $TimeOUT );
curl_setopt($curl, CURLOPT_TIMEOUT , $TimeOUT );
curl_setopt($curl, CURLOPT_HEADER , 0 );
curl_setopt($curl, CURLOPT_RETURNTRANSFER , 1 );
if( $Headers )
{
curl_setopt($curl, CURLOPT_HTTPHEADER , $Headers );
}
$data['content'] = curl_exec($curl);
$data['error'] = curl_error($curl);
$data['info'] = curl_getinfo($curl);
curl_close($curl);
return $data;
}