php http_build_query stream_context_create post请求
<?php
function send_post($url, $post_data)
{
$postdata = http_build_query($post_data);
$options = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type:application/x-www-form-urlencoded',
'content' => $postdata,
'timeout' => 15 * 60 // 超时时间(单位:s)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context); echo $result;
} //使用方法
$post_data = array(
'a' => '11',
'b' => '22'
);
send_post('http://localhost/b.php', $post_data);
php http_build_query stream_context_create post请求的更多相关文章
- 从API请求数据的方法(主要适用于tp5)
// 从api获取数据,$data是一个数组,默认为空,请求数据的方法可以通用,但是其它说明只适用于tp5 function postData($url,$data=''){ $ch = curl_i ...
- php使用curl下载指定大小的文件
php中使用基于libcurl的curl函数,可以对目标url发起http请求并获取返回的响应内容.通常的请求方式类似如下的代码: public function callFunction($url, ...
- curl 向远程服务器传输file文件
public function upload(){ //获取上传文件信息,文件名称以自己实际上传文件名称为准 $fileinfo = $_FILE['filename']; //请求参数,依据商户自己 ...
- 通过 curl 传递数据
方法一(若为post方式,只适用于一维数组) /** * curl发送htpp请求 * 可以发送https,http,get方式,post方式,post数据发送 */ public function ...
- PHP 获取IP地址位置信息「聚合数据API」
聚合数据 提供了[查询IP所属区域]的服务接口,只需要以 GET 请求的方式向 API 传入 IP地址 和 APPKEY 即可获得查询结果. 这里的难点主要在于如何通过PHP获取客户端IP地址,以及如 ...
- PHP:第五章——字符串编码函数
<?php header("Content-Type:text/html;charset=utf-8"); //1.base64_encode和base64_decode.6 ...
- 常用PHP方法
个人常用的一些方法记录/** * 返回错误 * * @param int $err_no * @param string $err_msg * @param array $data * @return ...
- PHP - 模拟HTTP请求, stream_context_create 和 fopen 和 fsockopen
一.fsocketopen,使用这个的过程看起来更像别的语言的socket编程 public function send($request) { /* 请求数据 */ $post_data = $re ...
- PHP使用http_build_query()构造URL字符串的方法(可将POST参数组转换拼接成GET请求链接)
<?php //parse_str与http_build_query的使用 //使用parse_str将url字符串转变为key=>value的数组 $str = "tn=mon ...
随机推荐
- django模板报错:Requested setting TEMPLATE_DEBUG, but settings are not configured. You must either define
转自:http://blog.csdn.net/xiaowanggedege/article/details/8651236 django模板报错: Requested setting TEMPLAT ...
- P4python: python interface to Perforce API
P4python is the python interface to Perforce API, it helps to do Perforce operations through python. ...
- mac crontab
1.前提工作 正常情况下mac普通用户是无法使用crontab的,需要做如下修改: 在~/.vimrc下添加这么一行: autocmd filetype crontab setlocal noback ...
- ubuntu 安装nodejs和git
1.安装curl sudo apt-get install curl 2.安装nodejs 和 npm curl -sL https://deb.nodesource.com/setup_8.x | ...
- QT的文件查找
https://blog.csdn.net/hustyangju/article/details/17784007 http://www.cppblog.com/biao/archive/2011/1 ...
- SVG基本图形
SVG 是使用 XML 来描述二维图形和绘图程序的语言 SVG 指可伸缩矢量图形 (Scalable Vector Graphics) SVG 用来定义用于网络的基于矢量的图形 SVG 使用 XML ...
- create-react-app部署到GitHub Pages时报错:Failed to get remote。origin.url
最近使用create-react-app脚手架开发了一个私人博客:点击跳转,在部署到GitHub Pages的时候报了一个错误,具体如下: 在create-react-app的GitHub库的issu ...
- [cocos2d-x]-会动的精灵
小鸟一直在扑翅膀的代码块: auto sprite = Sprite::create(); Animation *animation = Animation::create(); animation- ...
- luogu3368树状数组模板2
题目链接:https://www.luogu.org/problemnew/show/P3368 题意:与模板1不同的是这题的操作是树状数组并不在行的区间更新和单点查找,如果按照模板1那样写肯定会T. ...
- tp3.2中的 I () 方法
I('get.id'); // 相当于 $_GET['id']