curl post数据
调用方式:
$header = self::getHeader();
$data = self::postUrl($url, $header); /**
* 组合Header
* @return type
*/
protected static function getHeader()
{
return ["AppKey: ".self::$appKey."\nNonce: ".self::$nonce."\nCurTime: ".self::getCurTime()."\nCheckSum: ".self::getCheckNum()."\nContent-Type: ".self::$content_type['get_token_type']."\n"];
} /**
* post方式访问云信服务器
* @param type $url
* @param array $header
* @return type
* @throws Exception
* @throws TmacClassException
*/
protected static function postUrl($url, array &$header)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, self::$apiTimeout);//*秒超时设置
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$curl_data = curl_exec($ch); //执行
$curl_errno = curl_errno($ch);//最後一次執行的错误号0-没有错误(int)
$curl_error = curl_error($ch);//返回错误信息 string
curl_close($ch);
if ($curl_errno > 0) {
throw new Exception("CURL connection ($url) error: " ."$curl_errno $curl_error",$curl_errno);
}
if ((int)$curl_errno === 0){
$result = json_decode($curl_data, true);
if (isset($result["error"])) {
$code = isset($result["code"]) ? $result["code"] : -1;
throw new TmacClassException("{$code} {$result['error']}", $code);
}
}else {
$result = $curl_error;
}
return $result;
}
curl post数据的更多相关文章
- curl提交数据时中文乱码
1.使用curl提交数据时中文乱码解决: <?php $testJSON=array('name'=>'中文字符串','value'=>'test'); foreach ( $tes ...
- php curl采集数据问题汇总
1. 使用curl获取网页数据提示: "curl: (6) Could not resolve host: xxx.xxx.com ; Name or service not known&q ...
- php curl 传递数据
<?php header("Content-type: text/html; charset=utf-8"); /** * curl 传递数据 */ class curl { ...
- Curl 请求数据多’1‘
今天做curl请求时遇到一个问题 数据请求回来,无缘无故多了1 加上这一行代码就就可以了:curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
- 通过 curl 传递数据
方法一(若为post方式,只适用于一维数组) /** * curl发送htpp请求 * 可以发送https,http,get方式,post方式,post数据发送 */ public function ...
- 使用 PHP Curl 做数据中转
流程 收集头部信息 收集请求数据 转换头部信息为 CURL 头部请求格式 使用 Curl 进行转发 收集 HTTP 头信息 function getAllHeaders() { $headers = ...
- Elasticsearch 使用 php curl 插入数据
<?php /** * Created by PhpStorm. * User: func7 * Date: 2018/11/8 * Time: 11:24 */ set_time_limit( ...
- php curl发送数据和文件
function mycurl($file, $url, $aid) { // 如果文件名是中文名,将中文字符编码转换一下 $file=iconv("UTF-8","gb ...
- php 接收curl json 数据
curl -H "Content-Type: application/json" http://127.0.0.1:8000 -X POST -d 'xxxx' php $strP ...
随机推荐
- vue结合element-ui 的select 全选问题
下拉列表多选 问题 通过操作 所有来进行全选 全不选问题 element-ui 中 select 记录下自己最近使用element-ui 中的 select多选问题 在element中默认是指单纯多选 ...
- 适配器模式(Adapter Pattern)/包装器
将一个类的接口转换成客户希望的另外一个接口.Adapter模式使得原本由于接口不兼容而不能一起工作的那些类可以在一起工作. 模式中的角色 目标接口(Target):客户所期待的接口.目标可以是具体的或 ...
- 网络编程之socketserver初识
网络编程之socketserver初识 Server #!/usr/bin/env python # @Author : "Wjl" # @Date : 2017/12/22 # ...
- Accesshelper.cs
using System; using System.Data; using System.Data.OleDb; using System.Collections; using System.IO; ...
- C++复习7.虚表的概念
C++ 类的虚表 20130929 关键技术:封装.继承.组合.虚函数.抽象基类.动态绑定.多态性等等 1.首先整理一下在阿里巴巴面试遇到的函数虚表的问题. 在C++中的Class中的函数式存储在Cl ...
- C++中几个值得分析的小问题(2)
下面有3个小问题,作为C++ Beginner你一定要知道错在哪里了. 1.派生类到基类的引用或指针转换一定“完美”存在? 一般情况,你很可能会认为:派生类对象的引用或指针转换为基类对象的引用或指针是 ...
- redis的list类型以及其操作
lists类型 给你个图;' lists类型以及操作List是一个链表结构,主要功能是push.pop.获取一个范围的所有值等等,操作中key理解为链表的名字.Redis的list类型其实就是每一个子 ...
- php远程文件包含截断问题
今天在学习<白帽子讲web安全>一书是,提到一个php远程文件包含漏洞 可以从攻击者服务器中的一个写好的攻击脚本中远程执行命令 服务器中有漏洞的页面代码为: #test.php#error ...
- Getting command line access to PHP and MySQL running MAMP on OSX
建立自己profile路径应该在/Users/yourname/,最后要运行. ./.profile使文件生效,和windows中给添加环境变量是一个道理,还可以看出linux和UNIX默认运行路径为 ...
- Chrome浏览器优化技巧
Chrome浏览器开发者工具Network窗口下,可以查看下载各组件所需的具体时间 根据上表进行简要分析—— Stalled(阻塞) 浏览器对同一个主机域名的并发连接数有限制,因此如果当前的连接数已经 ...