调用方式:
$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数据的更多相关文章

  1. curl提交数据时中文乱码

    1.使用curl提交数据时中文乱码解决: <?php $testJSON=array('name'=>'中文字符串','value'=>'test'); foreach ( $tes ...

  2. php curl采集数据问题汇总

    1. 使用curl获取网页数据提示: "curl: (6) Could not resolve host: xxx.xxx.com ; Name or service not known&q ...

  3. php curl 传递数据

    <?php header("Content-type: text/html; charset=utf-8"); /** * curl 传递数据 */ class curl { ...

  4. Curl 请求数据多’1‘

    今天做curl请求时遇到一个问题 数据请求回来,无缘无故多了1 加上这一行代码就就可以了:curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

  5. 通过 curl 传递数据

    方法一(若为post方式,只适用于一维数组) /** * curl发送htpp请求 * 可以发送https,http,get方式,post方式,post数据发送 */ public function ...

  6. 使用 PHP Curl 做数据中转

    流程 收集头部信息 收集请求数据 转换头部信息为 CURL 头部请求格式 使用 Curl 进行转发 收集 HTTP 头信息 function getAllHeaders() { $headers = ...

  7. Elasticsearch 使用 php curl 插入数据

    <?php /** * Created by PhpStorm. * User: func7 * Date: 2018/11/8 * Time: 11:24 */ set_time_limit( ...

  8. php curl发送数据和文件

    function mycurl($file, $url, $aid) { // 如果文件名是中文名,将中文字符编码转换一下 $file=iconv("UTF-8","gb ...

  9. php 接收curl json 数据

    curl -H "Content-Type: application/json" http://127.0.0.1:8000 -X POST -d 'xxxx' php $strP ...

随机推荐

  1. 【hive】子查询

    hive中是不支持子查询的 但是并不意味这不支持in 或者 not in in 或者not in 后边是定值的话是支持的 但是接定制是可以的 例如 select id from table not i ...

  2. 转载:【Oracle 集群】RAC知识图文详细教程(四)--缓存融合技术和主要后台进程

    文章导航 集群概念介绍(一) ORACLE集群概念和原理(二) RAC 工作原理和相关组件(三) 缓存融合技术(四) RAC 特殊问题和实战经验(五) ORACLE 11 G版本2 RAC在LINUX ...

  3. centos静默安装oracle12c

    配置系统和安装所需软件包 关闭selinux 临时关闭(不用重启) [root@SVR-3-125 ~]# setenforce 0 修改配置文件(需要重启):  将SELINUX=enforcing ...

  4. 定位CPU高问题三把斧

    1.top -H -p PID 查看对应进程的哪个线程占用CPU过高 2.printf "%x\n" tid   将需要的线程ID转换为16进制格式 3.jstack pid &g ...

  5. vscode 实用插件

    1.Auto Rename Tag,非常实用!要修改标签名称的时候自动修改结束标签,节省一半时间,提升效率,非常棒! 2.vscode-icon,这款必须要推荐,明显提升效率的小插件,在项目文件多类型 ...

  6. 在IE中MVC控制器中返回JSON格式的数据时提示下载

    最近做项目时,视图中用jquery.form.js异步提交表单时,接收的是JSON格式的数据,但是奇怪的是在IE中提示下载文件,其他浏览器中一切正常,下载后,里面的内容就是在控制器中返回的数据.代码如 ...

  7. Python自定义大小截屏

    蝈蝈这两天正忙着收拾家当去公司报道,结果做PHP的发小蛐蛐找到了他,说是想要一个可以截图工具. 大致需要做出这样的效果. 虽然已经很久不写Python代码了,但是没办法,盛情难却啊,只好硬着头皮上了. ...

  8. 目标检测 - Tensorflow Object Detection API

    一. 找到最好的工具 "工欲善其事,必先利其器",如果你想找一个深度学习框架来解决深度学习问题,TensorFlow 就是你的不二之选,究其原因,也不必过多解释,看过其优雅的代码架 ...

  9. online learning,batch learning&批量梯度下降,随机梯度下降

    以上几个概念之前没有完全弄清其含义及区别,容易混淆概念,在本文浅析一下: 一.online learning vs batch learning online learning强调的是学习是实时的,流 ...

  10. tableView 三级展开 嵌入collocationView

    目前有个需求,需要在写一个文件夹结构的类型,tableView分类显示 collocationView 遇到的问题是:tableView cell中嵌套了 collocationView 后,coll ...