本文目录一览:
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 );
curl返回变量
将 a b两个变量组成字符串或者用json格式输出, curl得到后,分析下就好了
curl命令怎么传数组
1.转换成json在传输
2.
//通过curl模拟post的请求;function SendDataByCurl($url,$data=array()){ //对空格进行转义
$url = str_replace(' ','+',$url); $ch = curl_init(); //设置选项,包括URL
curl_setopt($ch, CURLOPT_URL, "$url");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch,CURLOPT_TIMEOUT,3); //定义超时3秒钟
// POST数据
curl_setopt($ch, CURLOPT_POST, 1); // 把post的变量加上
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); //所需传的数组用http_bulid_query()函数处理一下
//执行并获取url地址的内容
$output = curl_exec($ch); $errorCode = curl_errno($ch); //释放curl句柄
curl_close($ch); if(0 !== $errorCode) { return false;
} return $output;
}