curl模拟
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模拟的更多相关文章
- CURL 模拟http提交
1:CURL模拟get提交 private function httpGet($url) { $curl = curl_init(); curl_setopt($curl, CURLOPT_RETUR ...
- PHP 之 CURL 模拟登陆并获取数据
1.CURL模拟登陆的流程和步骤 2.tempnam 创建一个临时文件 3.使用CURL模拟登陆到PHP100论坛 <?php $cookie_file = tempnam('./temp',' ...
- curl模拟自动登陆&采集网页数据
<!DOCTYPE> <html> <head> <meta http-equiv="Content-Type" content=&quo ...
- php 的curl 模拟登陆
做一个类似这样的web 应用. 1,解决掉验证码 其实这是正方的一个小bug,当我们进入登陆界面时,浏览器会去请求服务器,服务器会生成一个验证码图片.如果我们不去请求这个图片,那么正方后台也不会生成相 ...
- 【转】PHP 之 CURL 模拟登陆并获取数据
1.CURL模拟登陆的流程和步骤2.tempnam 创建一个临时文件3.使用CURL模拟登陆到PHP100论坛 <?php$cookie_file = tempnam('./temp','coo ...
- php curl模拟post请求提交数据
最近在做校园图书馆图书信息的采集程序,既然是图书馆图书的采集,肯定有提交搜索的页面,无非是post提交,让我想到了curl模拟提交,首先通过firebug进行抓包查询下post提交后的格式如下: tx ...
- php curl模拟post请求提交数据样例总结
在php中要模拟post请求数据提交我们会使用到curl函数,以下我来给大家举几个curl模拟post请求提交数据样例有须要的朋友可參考參考.注意:curl函数在php中默认是不被支持的,假设须要使用 ...
- 使用curl模拟ip和来源进行网站采集的实现方法
对于限制了ip和来源的网站,使用正常的采集方式是不行的.本文将介绍一种方法,使用php的curl类实现模拟ip和来源,实现采集限制ip和来源的网站. 1.设置页面限制ip和来源访问 server.ph ...
- php中curl模拟post提交多维数组(转载)
原文地址:http://www.cnblogs.com/mingaixin/archive/2012/11/09/2763265.html 今天需要用curl模拟post提交参数,请求同事提供的一个接 ...
- php封装curl,模拟POST和GET请求HTTPS请求
<?php /** * @title 封装代理请求 * @author victor **/ class ApiRequest { /** * curl提交数据 * @param String ...
随机推荐
- 01 语言基础+高级:1-10 JDK8新特性_day12【函数式接口】
day12[函数式接口] 主要内容自定义函数式接口函数式编程常用函数式接口 教学目标能够使用@FunctionalInterface注解能够自定义无参无返回函数式接口能够自定义有参有返回函数式接口能够 ...
- python使用rsa非对称加密
1.安装rsa 支持python 2.7 或者 python 3.5 以上版本 使用豆瓣pypi源来安装rsa pip install -i https://pypi.douban.com/simpl ...
- DNS服务器搭建与配置
DNS服务器搭建与配置目录 1.DNS查询方式 2.DNS服务器类型 3.DNS主要配置文件组 4.name.conf文件配置介绍 5.DNS的资源记录格式 6.DNS服务器和客户端配置 7.简单搭建 ...
- 关于SpringMVC的使用总结
简介 springMVC即Spring Web MVC,是spring web模块的一部分,是spring自己的web框架 springMVC对Servlet API 进行了完善的封装,极大的简化了开 ...
- springBoot 使用redis 和 StringRedisTemplate 常用操作
spring boot 使用 redis : 1,pom 引入 redis,貌似springboot 1.5以上的版本,引入redis必须加 <version></version&g ...
- TensorFlow 实例一(一元线性回归)
使用TensorFlow进行算法设计与训练的核心步骤: 准备数据 构建模型 训练模型 进行预测 问题描述: 通过人工数据集,随机生成一个近似采样随机分布,使得w = 2.0 ,b= 1,并加入一个噪声 ...
- Servlet&JSP复习笔记 01
1. Servlet 含义:服务器端的小程序,它只是服务器中的一部分. Servlet Little 标准:Sun公司制定的一种用来扩展Web服务器功能的组件规范. a. 扩展web服务器功能:扩展w ...
- 拾起HTML+CSS的一天
今天在w3school看了下HTML5和CSS3的新特性. 本来觉得自己对CSS方面基础还挺有把握的,就之前自学都是跳过这个模块的,但经过昨天会友的面试,感觉自己好像太忽视基础了,很多基本的东西很模糊 ...
- shell里脚本里写个简单的函数,显示颜色
如果多次用到颜色显示,还是定义一个函数比较实在,具体什么颜色上网找一下 #!/bin/bash # 定义一个红色显示的函数 function echo_red () { local what=$* e ...
- 上传excel文件,读取内容,增加事务写入数据库
package com.inspur.icpmg.itss.asset.dao.impl; import com.inspur.icpmg.util.DBHelper; import org.apac ...