header(‘content-type:text/html;charset=utf-8’);
function curlPost($url,$data,$method){
$ch = curl_init(); //1.初始化
curl_setopt($ch, CURLOPT_URL, $url); //2.请求地址
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);//3.请求方式
//4.参数如下
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);//https
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_USERAGENT, ‘Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)’);//模拟浏览器
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER,array(‘Accept-Encoding: gzip, deflate’));//gzip解压内容
curl_setopt($ch, CURLOPT_ENCODING, ‘gzip,deflate’);

if($method=="POST"){//5.post方式的时候添加数据
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$tmpInfo = curl_exec($ch);//6.执行 if (curl_errno($ch)) {//7.如果出错
return curl_error($ch);
}
curl_close($ch);//8.关闭
return $tmpInfo;

}
$data=array(‘name’ => ‘1234’);
$url=”http://www.sohu.com/“;

$method=”GET”;
$file=curlPost($url,$data,$method);
$file=mb_convert_encoding($file,’UTF-8’,’GBK’);
echo $file;

当cookie认证登陆的时候
[php] view plain copy 在CODE上查看代码片派生到我的代码片
<?php
$cookie_file = tempnam(‘./temp’,’cookie’);
function weixinPost($url,$data,$method,$setcooke=false,$cookie_file=false){
$ch = curl_init(); //1.初始化
curl_setopt($ch, CURLOPT_URL, $url); //2.请求地址
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);//3.请求方式
//4.参数如下
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE 大专栏  curl模拟);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_USERAGENT, ‘Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)’);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);

    if($method=="POST"){//5.post方式的时候添加数据
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
if($setcooke==true){
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
}else{
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$tmpInfo = curl_exec($ch);//6.执行 if (curl_errno($ch)) {//7.如果出错
return curl_error($ch);
}
curl_close($ch);//8.关闭
return $tmpInfo;
}
$data=array('username' => '***','password'=>'***');
$url="http://www.xinxinj.com/login.php";
$method="POST";
$file=weixinPost($url,$data,$method,true,$cookie_file);
echo $file; $url="http://www.xinxinj.com/admin.php";
$method="GET";
$file=weixinPost($url,$data,$method,false,$cookie_file);
echo $file;

?>

如果上述还是无法解决,那么采用以下方案
[php] view plain copy 在CODE上查看代码片派生到我的代码片
$ch = curl_init();
$url = ‘*‘;
$header = array(
‘cookie:**
);
// 添加apikey到header
curl_setopt($ch, CURLOPT_HTTPHEADER , $header);
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, ‘Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:50.0) Gecko/20100101 Firefox/50.0’);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
// 执行HTTP请求
curl_setopt($ch , CURLOPT_URL , $url);
$res = curl_exec($ch);
var_dump($res);

上面的$header中的数组中cookie的内容是现在浏览器登录,然后打开控制台,把cookie的信息粘贴进来


curl模拟的更多相关文章

  1. CURL 模拟http提交

    1:CURL模拟get提交 private function httpGet($url) { $curl = curl_init(); curl_setopt($curl, CURLOPT_RETUR ...

  2. PHP 之 CURL 模拟登陆并获取数据

    1.CURL模拟登陆的流程和步骤 2.tempnam 创建一个临时文件 3.使用CURL模拟登陆到PHP100论坛 <?php $cookie_file = tempnam('./temp',' ...

  3. curl模拟自动登陆&采集网页数据

    <!DOCTYPE> <html> <head> <meta http-equiv="Content-Type" content=&quo ...

  4. php 的curl 模拟登陆

    做一个类似这样的web 应用. 1,解决掉验证码 其实这是正方的一个小bug,当我们进入登陆界面时,浏览器会去请求服务器,服务器会生成一个验证码图片.如果我们不去请求这个图片,那么正方后台也不会生成相 ...

  5. 【转】PHP 之 CURL 模拟登陆并获取数据

    1.CURL模拟登陆的流程和步骤2.tempnam 创建一个临时文件3.使用CURL模拟登陆到PHP100论坛 <?php$cookie_file = tempnam('./temp','coo ...

  6. php curl模拟post请求提交数据

    最近在做校园图书馆图书信息的采集程序,既然是图书馆图书的采集,肯定有提交搜索的页面,无非是post提交,让我想到了curl模拟提交,首先通过firebug进行抓包查询下post提交后的格式如下: tx ...

  7. php curl模拟post请求提交数据样例总结

    在php中要模拟post请求数据提交我们会使用到curl函数,以下我来给大家举几个curl模拟post请求提交数据样例有须要的朋友可參考參考.注意:curl函数在php中默认是不被支持的,假设须要使用 ...

  8. 使用curl模拟ip和来源进行网站采集的实现方法

    对于限制了ip和来源的网站,使用正常的采集方式是不行的.本文将介绍一种方法,使用php的curl类实现模拟ip和来源,实现采集限制ip和来源的网站. 1.设置页面限制ip和来源访问 server.ph ...

  9. php中curl模拟post提交多维数组(转载)

    原文地址:http://www.cnblogs.com/mingaixin/archive/2012/11/09/2763265.html 今天需要用curl模拟post提交参数,请求同事提供的一个接 ...

  10. php封装curl,模拟POST和GET请求HTTPS请求

    <?php /** * @title 封装代理请求 * @author victor **/ class ApiRequest { /** * curl提交数据 * @param String ...

随机推荐

  1. openvino资源

    Intel OpenVINO介紹及樹莓派.Linux的安裝 https://chtseng.wordpress.com/2019/01/21/intel-openvino%E4%BB%8B%E7%B4 ...

  2. mysql 创建帐号出现 Access denied for user 'root'@'localhost'错误(转载)

    从供应商那边接手一个MySQL数据库(数据库版本为5.7.21 MySQL Community Server (GPL)),在创建账号时遇到了“ERROR 1044 (42000): Access d ...

  3. netty 百度网盘 密码

    netty基础 https://pan.baidu.com/s/1v_ME49LIef1Kwga8z2QbDw?spm=a1z09.2.0.0.680b2e8d5LI8S0   zb7u mina n ...

  4. Go-开发环境搭建

    02-开发环境搭建   目录 一 下载地址 二 安装 Linux安装 Windows安装 Mac安装 三 测试安装 四 命令介绍 基本介绍 build 和 run 命令 get 命令 一 下载地址 安 ...

  5. ZJNU 2201 - 挖矿谷物语

    在dfs过程中加上栈记录当次dfs走过的路径 如果当次dfs到了一个之前的dfs已经经过的点 又因为只对没有访问过的点开始dfs 所以这种情况就说明接下来不可能返回到当次dfs开始的点 将栈内元素取出 ...

  6. ubuntu14 编译tensorflow C++ 接口

    tensorflow1.11 bazel 0.15.2 protobuf 3.6.0 eigen 3.3.5 wget -t 0 -c https://github.com/eigenteam/eig ...

  7. 第04项目:淘淘商城(SpringMVC+Spring+Mybatis)【第十天】(单点登录系统实现)

    https://pan.baidu.com/s/1bptYGAb#list/path=%2F&parentPath=%2Fsharelink389619878-229862621083040 ...

  8. java gc 总结

    垃圾查找 1.基于计数器 对象有引用计数,计数为0的,可以被收集 2.基于有向图 从gc root(栈.静态变量.JNI 变量)遍历,能访问的对象,不用被收集,其他的,可以被收集 因为计数器不能解决 ...

  9. javaScript 面向对象 触发夫级构造函数

    class Person{ constructor(name,age){ //直接写属性 this.name=name; this.age=age; console.log('a'); } showN ...

  10. hdu 6035 Colorful Tree(虚树)

    考虑到树上操作:首先题目要我们求每条路径上出现不同颜色的数量,并把所有加起来得到答案:我们知道俩俩点之间会形成一条路径,所以我们可以知道每个样例的总的路径的数目为:n*(n-1)/2: 这样单单的求, ...