php curl会话

来源:互联网 发布:装饰公司预算软件 编辑:程序博客网 时间:2024/05/29 07:43
<?phpfunction call() {$url = "http://dede.me/plus/task/taskone.php";$data='test=1&test2=2';//启动一个CURL会话$ch = curl_init();// 设置curl允许执行的最长秒数curl_setopt($ch, CURLOPT_TIMEOUT, '30');// 获取的信息以文件流的形式返回,而不是直接输出。curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);//发送一个常规的POST请求,类型为:application/x-www-form-urlencoded,就像表单提交的一样。curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_URL,$url);//要传送的所有数据curl_setopt($ch, CURLOPT_POSTFIELDS, $data);// 执行操作$res = curl_exec($ch);$responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);if ($res == NULL) {    echo  "call http err :" . curl_errno($ch) . " - " . curl_error($ch) ;   curl_close($ch);   return false;} else if($responseCode  != "200") {echo "call http err httpcode=" . $responseCode  ;curl_close($ch);return false;}curl_close($ch);var_dump($res);return true;} call();?>


	
				
		
原创粉丝点击