//默认模拟的header头
private function _defaultHeader() {
$header = "User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12\r\n";
$header.="Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n";
$header.="Accept-language: zh-cn,zh;q=0.5\r\n";
$header.="Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7\r\n";
return $header;
}
private function post($url, $post_data=array(), $timeout=5, $header="") {
$header = empty($header) ? self::_default_header() : $header;
$post_string = http_build_query($post_data);
$header.="Content-length: " . strlen($post_string);
$opts = array(
'http' => array(
'protocol_version' => '1.0', //http协议版本(若不指定php5.2系默认为http1.0)
'method' => "POST", //获取方式
'timeout' => $timeout, //超时时间
'header' => $header,
'content' => $post_string)
);
$context = stream_context_create($opts);
//为解决接口超时
$cnt=0;
while($cnt < 3 && ($str=@file_get_contents($url, false, $context))===FALSE)
$cnt++;
return $str;
}

file_get_contents post数据的更多相关文章

  1. PHP中fopen,file_get_contents,curl函数的区别

    PHP中fopen,file_get_contents,curl函数的区别 1.fopen/file_get_contents每次请求都做DNS查询,并不对DNS的信息进行缓存,而curl会对DNS的 ...

  2. 给file_get_contents函数设置超时时间

    $opts = array( 'http'=>array( 'method'=>"GET", 'timeout'=>60, ) ); $context = str ...

  3. php远程连接http方式

    以下这三者是通过GET方式来获取数据 1.socket 方式 一般是指定网址.端口号.超时时间. 再对报头进行修改以及传递参数,包括:header.method.content, 返回的内容包括hea ...

  4. file_get_contents模仿浏览器头(user_agent)获取数据

    本篇文章是对file_get_contents模仿浏览器头(user_agent)获取数据进行了详细的分析介绍,需要的朋友参考下     什么是user agentUser Agent中文名为用户代理 ...

  5. PHP file_get_contents函数读取远程数据超时的解决方法

    PHP file_get_contents函数读取远程数据超时的解决方法 投稿:junjie 字体:[增加 减小] 类型:转载   这篇文章主要介绍了PHP file_get_contents函数读取 ...

  6. file_get_contents无法获取数据的一种情况

    下面这段php代码突然不好使了,返回的 $html 为空,百思不得解.网上说法好多,但都是一家之言,解决不了我的问题.(我的解决方法也是一家之言,只能解决file_get_contents获取不到数据 ...

  7. php中使用Curl、socket、file_get_contents三种方法POST提交数据

    抓取远程内容,之前一直都在用file_get_content函数,其实早就知道有curl这么一个好东西的存在,但是看了一眼后感觉使用颇有些复杂,没有file_get_content那么简单,再就是需求 ...

  8. file_get_contents函数获取不到数据的一种情况

    问题:  file_get_contents($url) 获取不到数据,尽管URL地址正确,函数使用正确.如下代码 $url = "https://www.baidu.com"; ...

  9. file_get_contents('php://input') 数据如何转换成数组

    前台表单页:demo01.html 后台:demo01.php 输出结果: 备注:若前台通过Ajax的post提交过来的是json数据,需要对json数据进行解析:$data = json_decod ...

随机推荐

  1. Linux程序设计 读笔2 Shell脚本

    第二章 Shell程序设计 四.管道和重定向 1 重定向输出 ls -l > lsoutput.txt ps >> lsoutput.txt >>表示附加到一个文件中 文 ...

  2. lightoj 1038 Race to 1 Again

    题意:给一个数,用这个数的因数除以这个数,直到为1时,求除的次数的期望. 设一个数的约数有M个,E[n] = (E[a[1]]+1)/M+(E[a[2]]+1)/M+...+(E[a[M]]+1)/M ...

  3. zabbix监控服务器部署

    1.服务器安装lamp环境 [root@monitor ~]# yum  install gcc gcc-c++ autoconf httpd php mysql mysql-server php-m ...

  4. Docker容器的数据管理

    Docker容器的数据管理 Docker容器的数据管理 什么是数据卷(Data Volume)? 数据卷是经过特殊设计的目录,可以绕过联合文件系统(UFS),为一个或者多个容器提供访问 数据卷设计的目 ...

  5. objective -c 知識点

    那么类别与继承相比,有什么缺点吗?类别不可以声明新的成员变量,而且一旦你定义的方法与原始类中的方法名称相同,那么原始方法将被隐藏起来,因为不是继承结构,你不能在类别中的方法使用super 激活原始类的 ...

  6. Zend Studio 12 大集合

    前言 本文记录了我个人使用Zend Studio 12的点点滴滴,不定时更新. 内容来源于网络,如有侵权,告知后可删除. 下载 官方链接点击链接,填入相关信息即可下载. 破解 声明:请购买正版,非万不 ...

  7. AndroidManifest.xml配置文件详解

    AndroidManifest.xml配置文件对于Android应用开发来说是非常重要的基础知识,本文旨在总结该配置文件中重点的用法,以便日后查阅.下面是一个标准的AndroidManifest.xm ...

  8. HTML5学习笔记之Input类型

    Input类型——email email类型用于包含email地址的输入域,在输入地址时会自动验证email域的值 例:Email:<input type="email" n ...

  9. 不要将 Array、Object 等类型指定给 prototype

    在 JavaScript 中,注意不要将 Array.Object 等类型指定给 prototype,除非您的应用需要那么做.先观察如下代码: function Foo(){}Foo.prototyp ...

  10. 深入Blocks分析

    1.简介 从iOS4开始,苹果引入了这个C语言的扩充功能"Blocks",在一些特定的场景下也是一把利刃.我前面一篇博客中初步介绍了Blocks这个东西,主要是语法的介绍(< ...