php用crul请求url资源方法makeRequest()
来源:互联网 发布:linux配置多个tomcat 编辑:程序博客网 时间:2024/06/08 07:55
function makeRequest($url, $argument = array(), $ttl = 5, $method = "GET", $cookie='', $follow=0){
if (!$url) {
throw new LogicException('$url不能为空');
}
if (substr($url, 0, 7) != 'http://' && substr($url, 0, 8) != 'https://') {
return array('result' => NULL, 'code' => '400');
}
if ($method == 'GET' && count($argument) > 0) {
$url .= "?" . (http_build_query($argument));
//echo $url;
}
$header = array(
'Accept-Language: zh-cn,zh;q=0.8',
'Connection: Keep-alive',
'Cache-Control: max-age=0'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
if ($method == 'POST') {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $argument);
}
if( file_exists($cookie) ){
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, $ttl);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1707.0 Safari/537.36');
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
if( $follow==1 ){
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
}
$return = array();
$return['result'] = curl_exec($ch);
$return['code'] = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
unset($ch);
return $return;
}
if (!$url) {
throw new LogicException('$url不能为空');
}
if (substr($url, 0, 7) != 'http://' && substr($url, 0, 8) != 'https://') {
return array('result' => NULL, 'code' => '400');
}
if ($method == 'GET' && count($argument) > 0) {
$url .= "?" . (http_build_query($argument));
//echo $url;
}
$header = array(
'Accept-Language: zh-cn,zh;q=0.8',
'Connection: Keep-alive',
'Cache-Control: max-age=0'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
if ($method == 'POST') {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $argument);
}
if( file_exists($cookie) ){
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, $ttl);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1707.0 Safari/537.36');
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
if( $follow==1 ){
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
}
$return = array();
$return['result'] = curl_exec($ch);
$return['code'] = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
unset($ch);
return $return;
}
0 0
- php用crul请求url资源方法makeRequest()
- PHP AppServ开启CRUL的方法说明
- PHP CRUL配置
- php请求远程url内容方法
- URL资源请求
- php crul 中文乱码问题解决
- GET方法请求URL
- POST方法请求URL
- PHP识别url重写请求
- PHP识别url重写请求
- php 中curl 循环去请求多个URL和多线程去请求多个URL的方法
- 发送url请求的方法
- 用Crul 命令 来调试服务器接口
- shouldOverrideUrlLoading(拦截url加载,除资源请求的url) shouldInterceptRequest(拦截所有url请求)
- php获取请求url时响应的报头信息几种方法
- php请求url过长改用curl
- php 获取url请求对应信息
- PHP模拟发送POST请求之二、用PHP和JS处理URL信息
- 写出下面程序的运行结果
- js根据客户端浏览器类型,判断跳转官网/手机网站
- C++指针解惑
- [BASIC-24] 龟兔赛跑预测
- 链栈的表示与实现
- php用crul请求url资源方法makeRequest()
- ynmyjtj
- Android修炼之道—可回弹的ListView
- 虚拟机下ubuntu的minicom使用指南
- 碳雕的相关知识
- vim命令常用用法
- 【剑指offer】八皇后问题
- C# WINFORM 某些控件实现联想输入功能
- 个人使用Linux操作系统常要做的事