$auth = base64_encode('LOGIN:PASSWORD');//LOGIN:PASSWORD 这里是你的账户名及密码
$aContext = array(
'http' => array(
'proxy' => 'tcp://192.168.0.2:3128',//这里设置你要使用的代理ip及端口号
'request_fulluri' => true,
'header' => "Proxy-Authorization: Basic $auth",
),
);
$cxContext = stream_context_create($aContext);
$sFile = file_get_contents(http://www.phpfensi.com, False, $cxContext);
echo $sFile;

<?php
function curl($url)
{
$str_url = $url;
$ch_curl = curl_init ();
curl_setopt ( $ch_curl, CURLOPT_TIMEOUT, 3 );
curl_setopt ( $ch_curl, CURLOPT_HEADER, false );
curl_setopt ( $ch_curl, CURLOPT_HTTPGET, 1 );
curl_setopt ( $ch_curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $ch_curl, CURLOPT_URL, $str_url ); //HTTP的代理
$proxy="192.168.168.251:80";
curl_setopt($ch_curl, CURLOPT_HTTPPROXYTUNNEL,true);
curl_setopt($ch_curl, CURLOPT_PROXYTYPE,CURLPROXY_HTTP);
curl_setopt($ch_curl, CURLOPT_PROXY, $proxy);
//curl_setopt($ch_curl, CURLOPT_PROXYUSERPWD, ''); /*
//Sock 4 的代理
curl_setopt($ch_curl, CURLOPT_PROXYTYPE,4);
//Sock 5 的代理
curl_setopt($ch_curl, CURLOPT_PROXYTYPE,5);
*/
$str_return = curl_exec ( $ch_curl );
if ($str_return === false)
{
return false;
}
curl_close ( $ch_curl );
return $str_return;
}
$url = "http://p1.img.cctvpic.com/xiyou/userimage/2012/10/18/163312135054919266639.jpg";
$contents = curl($url);
var_dump($contents);
file_put_contents("/tmp/1p.jpg",$contents);
?>

php file_get_contents curl发送cookie,使用代理的更多相关文章

  1. PHP下通过file_get_contents\curl的方法实现获取远程网页内容(别忘了还有PhpRPC)

    [php]PHP中file_get_contents()与file_put_contents()函数细节详解 php函数file_get_contents(一) 案例: 早在2010年时候遇到过这样的 ...

  2. 使用curl传递cookie错误的问题

    工作中发现一个问题, 通过curl调用接口传递cookie操作用户的数据, 接口的程序解析不了cookie中的数据. 经过排查发现curl发送的cookie数据为 TZ+Gn+rEk+6G4d 而接口 ...

  3. 简单设置,解决使用webpack前后端跨域发送cookie的问题

    最近用vue来做项目,用webpack来做前端自动化构建.webpack-dev-server会在本地搭建一个服务器,在和后端调试的时候,就会涉及到跨域的问题. 刚开始时,没有用vue-cli来构建项 ...

  4. windows下nginx+fastcgi不能使用file_get_contents/curl/fopen的原因

    这两天一直在搞windows下nginx+fastcgi的file_get_contents请求.我想,很多同学都遇到当file_get_contents请求外网的http/https的php文件时毫 ...

  5. php使用curl带cookie访问一直失败求助

    最近需要批量向织梦后台导入一些数据,但是遇到了一个头疼的问题. 环境:xampp + 别人的dede后台. 首先,利用curl发送post请求登录login.php,成功,并且保存了cookie文件. ...

  6. php通过curl发送XML数据,并获取XML数据

    php编程中经常会用到用xml格式传送数据,如调用微信等第三方接口经常用到,这里演示下php以curl形式发送xml,并通过服务器接收 一.发送xml数据 -- postXml.php <?ph ...

  7. 跨域问题,前端主动向后台发送cookie

    跨域是什么? 从一个域名的网页访问另一个域名的资源,就会出现跨域.只要协议.端口.域名有一个不同就会出现跨域 例如: 1.协议不同  http://www.baidu.com:80 和 https:/ ...

  8. curl发送请求时携带cookie-转载未验证

    <?php header('Content-Type:text/html;charset=utf-8'); echo "<pre>"; function curl ...

  9. Android端接收和发送cookie

    流程: 首先android端使用HttpClient的方式发送HTTP请求,此时服务器创立cookie,并发送cookie给android端,android端再将cookie保存起来,在需要发送coo ...

随机推荐

  1. poj2079Triangle(N点中三点组成三角形面积最大)

    链接 根据旋转卡壳的思想,找到当前边的最远点. 确定i,j找到最远的k使 cross(i,j,k)最大,那么i,j+1时只需从k+1开始找即可 . #include <iostream> ...

  2. Oracle分析函数的项目实践实例

    SELECT * FROM SSE2_FLOW_EXPENSE T1 JOIN (SELECT SFEL.*, ROW_NUMBER() OVER(PARATITION BY SFEL.FE_EXPE ...

  3. Docker-数据卷和数据容器卷

    容器中管理数据主要有两种方式: 数据卷(Data Volumes) 数据卷容器(Data Volumes Dontainers) 数据卷 使用-v可以挂载一个本地的目录到容器中作为数据卷. [root ...

  4. 提高iOS开发效率的第三方框架等

    http://zhangmingwei.iteye.com/blog/2208783 http://www.kuqin.com/shuoit/20150703/346900.html

  5. 【linux命令】grep

    1.作用Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来.grep全称是Global Regular Expression Print,表示全局 ...

  6. Asp.net_Webservice返回json

    [WebMethod] public List<PictureManager> LoadPictureOne() { dataDataContext context = new dataD ...

  7. OpenCV3编程入门笔记(1)图像载入、显示、保存、变换灰度图

    图像载入.显示.保存函数: 1         图像载入函数:imread()   Mat imread(const string& filename, int flags=1); const ...

  8. phalcon: eventManager事件管理(结合dispatcher调度控制器)制作简单的acl

    制作简单的acl, dispatcher(专门用来加载或调度或跳转到相应的url地址即XXXcontroller的调度器或控制器,能够在controller执行前对controller进行停止跳转等) ...

  9. wps的几个优点

    wps的几个优点 1.wps非常小巧,wps2011源文件38M,安装后160M,wps2010安装过后158M,工具栏.程序设置.模板可保存在一个文件里面,重装后用\WPS Office Perso ...

  10. 联想G480笔记本安装系统

    联想G480笔记本安装系统 联想G480笔记本,配置i5双核四线程处理器,4G内存,500G硬盘,USB3.0接口,NVIDIA GeForce GT 610M+Intel HD Graphics 3 ...