调用方式:
$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. linux下面安装maven

    maven作为最近比较火的项目管理工具,对项目的jar包及其开元添加相应的插件的管理,很方便. 安装maven: 在官网上面去下载最新的maven的压缩包,apache-maven-3.3.1-bin ...

  2. js获取显示器、页面等高度 (转)

    网页可见区域宽:document.body.clientWidth网页可见区域高:document.body.clientHeight网页可见区域宽:document.body.offsetWidth ...

  3. C++复习1.内存管理的知识

    C++ 内存管理 1.内存分配的方式有三种: 从静态存储区分配:在程序编译期间已经分配好了,这些在程序的生命周期内都是有效的,如全局变量,static变量 一个例子: char * p = " ...

  4. Bing的Translation API 接入

    参考: https://msdn.microsoft.com/zh-cn/library/mt146806.aspx 首先你需要一个Microsoft的帐号,如果没有在这里注册一下 https://s ...

  5. 通过Fegin远程调用 ,返回JPA Page 对象报错

    Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of org.sp ...

  6. CMDB开发(需求分析)

    浅谈ITIL TIL即IT基础架构库(Information Technology Infrastructure Library, ITIL,信息技术基础架构库)由英国政府部门CCTA(Central ...

  7. 做网站用UTF-8还是GB2312?

    经常我们打开外国网站的时候出现乱码,又或者打开很多非英语的外国网站的时候,显示的都是口口口口口的字符, WordPress程序是用的UTF-8,很多cms用的是GB2312. ● 为什么有这么多编码? ...

  8. 在servlet中的中文乱码,相对路径和绝对路径

    默认情况下在servlet中的中文是显示不出来的,解决问题就是加resp.setContentType("text/html;charset=gbk"); 而且这句加的话必须写在P ...

  9. C++ writestring 为什么不能写进中文 CStdioFile向无法向文本中写入中文【二】

    本地化设置需要具备三个条件:a. 语言代码 (Language Code)b. 国家代码 (Country Code) c. 编码(Encoding)本地名字可以用下面这些部分来构造:语言代码_国家代 ...

  10. 【译】从数学公式入手,详细了解 Animation 的 Interpolators

    我们在做动画的时候,总是避免不了会使用到 Interpolator(插值器)这个东西,比如 LinearInterpolator 等.这样做的好处是,能够让动画的变化速度符合现实世界中的物理规律,看上 ...