调用方式:
$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. 伪共享(False Sharing)和缓存行(Cache Line)

    转载:https://www.jianshu.com/p/a9b1d32403ea https://www.toutiao.com/a6644375612146319886/ 前言 在上篇介绍Long ...

  2. webmin 安装

    webmin 安装1.下载:wget http://prdownloads.sourceforge.net/webadmin/webmin-1.850-1.noarch.rpm2.安装依赖环境:yum ...

  3. HDU 4549 M斐波那契数列(矩阵快速幂+费马小定理)

    M斐波那契数列 Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other) Total Submi ...

  4. vue 侧边导航栏递归显示

    import axios from "axios"; import tabs1 from "../tab_content/tab1.vue"; import m ...

  5. LeetCode OJ:Generate Parentheses(括号生成)

    Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthes ...

  6. certbot以standalone方式新建密钥

    下载:wget https://dl.eff.org/certbot-auto 授权:chmod a+x ./certbot-auto 快捷命令 ./certbot-auto certonly --t ...

  7. web服务器无法显示font-awesome字体图标

    今天遇到了在本地运行网页 一切调用的额font的小图标都OK的,但是把网页发布到tomcat服务器上面就不行了 之后百度了下,找到了解决方法,遂记录下,方法如下: 在web.xml 文件中加上: &l ...

  8. Django部署时为什么要用 uWSGI与 Nginx? 以及 WSGI,uwsgi等协议

    Django框架的服务器架构一般是 Nginx + uWSGI + Django (1)一些基本概念 1 WSGI协议,uwsgi协议 WSGI协议(通讯协议):Python用于Web开发的协议(用于 ...

  9. html2canvas 截屏 兼容手机端

    <template> <div> <!--<input type="button" id="btnsavaImg" valu ...

  10. Java中级面试题——(上)

    List和Set比较,各自的子类比较 对比一:Arraylist与LinkedList的比较 1.ArrayList是实现了基于动态数组的数据结构,因为地址连续,一旦数据存储好了,查询操作效率会比较高 ...