<?php function 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(); ?>
php curl会话
最新推荐文章于 2023-11-10 17:41:01 发布