php curl请求转发
[php] view plain copy
- <?php
- function get_url_content($url){
- $user_agent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)";
- $ch = curl_init();
- //curl_setopt ($ch, CURLOPT_PROXY, $proxy);
- curl_setopt ($ch, CURLOPT_URL, $url);//设置要访问的IP
- curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);//模拟用户使用的浏览器
- @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1 ); // 使用自动跳转
- curl_setopt ($ch, CURLOPT_TIMEOUT, 60); //设置超时时间
- curl_setopt ($ch, CURLOPT_AUTOREFERER, 1 ); // 自动设置Referer
- curl_setopt ($ch, CURLOPT_COOKIEJAR, 'c:cookie.txt');
- curl_setopt ($ch, CURLOPT_HEADER,0); //显示返回的HEAD区域的内容
- curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
- curl_setopt ($ch, CURLOPT_TIMEOUT, 10);
- $result = curl_exec($ch);
- curl_close($ch);
- return $result;
- }
- print_r(get_url_content('http://www.baidu.com'));
- ?>
-----------------------------------------------------------------------------------------
还可以用下面方式实现请求转发
[php] view plain copy
- print_r(file_get_contents('http://www.baidu.com'));
相关推荐
- 请求转发的实现及其优缺点
- PHP 中的CURL 模拟表单的post提交
- PHP开启cURL功能
- JavaWeb08-请求转发和重定向的区别
- 请求转发与请求重定向
- PHP:cURL error 60: SSL certificate problem: unable to get local issuer certificate
- 根据XML文档 PHP实现SOAP请求WSDL
- PHP CURL
- Nginx配置TCP请求转发
- ajax数据请求5(php格式) ajax数据请求5(php格式):
- 每天一个linux命令(15):tail 命令
- Node.js开发Web后台服务 原文转至:http://www.cnblogs.com/best/p/6204116.html 一、简介 二、搭建Node.js开发环境 三、第一个Node.js程序 四、NPM(Node.js包管理器) 五、Express 六、RESTful(表述性状态转移) 七、示例下载