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. Android通过包名打开第三方应用

    import android.content.ComponentName; import android.content.Context; import android.content.Intent; ...

  2. python数据预处理for knn

    机器学习实战 一书中第20页数据预处理,从文本中解析数据的程序. import numpy as np def dataPreProcessing(fileName): with open(fileN ...

  3. git submodule update --init 和 --remote的区别

    git 的submodule 工具方便第三方库的管理,比如gitlab 上的各种开源工具,spdlog等 在项目目录下创建.gitmodule 里可以添加第三方库,然后在更新第三方库时,有两个选项 g ...

  4. 微信小程序使用第三方FontIcon库的部分字体图标

    一.提取部分图标重新制作TTF字库 我没有使用网上大多数文章写的淘宝提供的fonticon,而只使用了Ionicons的几个图标,所以打开Ionicons的官网点击右上角的Designer pack下 ...

  5. python_pycharm控制台输出带颜色

    一.书写格式: 设置颜色开始:\033[显示方式;前景色;背景色m] 结束:\033[0m 二.颜色参数: 前景色 背景色 颜色 ----------------------------------- ...

  6. ERP上线通用模板

    一.引言    随着现代信息技术的发展与广泛应用,现代社会的快速发展和越来越追求效率的现状,对各行各业的管理的水平有了进一步的提高.XX企业作为我国的国民经济发展的基础产业,其信息化建设的水平直接关系 ...

  7. liblinear中的信赖域算法

    求方程 \(H s = -g\), H是hessian矩阵, g 为梯度, 残量 \(r = -g -Hs\). s的初值为0,理论上,共轭梯度每步迭代使得\(\|s\|\) 单调增加,共轭梯度的迭代 ...

  8. 14 微服务电商【黑马乐优商城】:day06-使用nginx反向代理并掌握cors解决跨域

    本项目的笔记和资料的Download,请点击这一句话自行获取. day01-springboot(理论篇) :day01-springboot(实践篇) day02-springcloud(理论篇一) ...

  9. PAT甲级——1077.Kuchiguse(20分)

    The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...

  10. idea新建maven项目后生成web.xml方法和添加到tomcat方法

    idea新建maven项目后生成web.xml方法和添加到tomcat方法 参考:https://www.cnblogs.com/Liang-Haishan216/p/9302141.html 1.首 ...