php curl扩展发送https post请求
来源:互联网 发布:网络的好处英语作文 编辑:程序博客网 时间:2024/04/28 02:28
最近在搞php开发公众号设置菜单。如果你也在纠结这个https请求要怎么发,还要支持中文菜单名,看这个就恰好了。
以下直接上代码
public function setMenu() {
//自己的accessToken $accessToken = 'Hqkmd87QdypVDqZ5xkoZkEpqJhRt-Cn2hd3HITyZq1f0bpje_KkfOjcTUG2eJ9AR-0q3R5rMpjNIaHr4K_iwNge5iBb6BvLX36axfHRMkssSNuPRvtLYnsggkLCN_9ixEAZfAIATPO'; $url = 'https://api.weixin.qq.com/cgi-bin/menu/create?access_token='.$accessToken; $data = array( 'button' => C('BUTTON_CONF'), ); $rep = $this->_post($url, json_encode($data, JSON_UNESCAPED_UNICODE));
//json_encode第二个参数很重要 确保中文菜单名不被转码成unicode 否则服务器会返回错误代码, 提示您里面有\\的编码 让你检查编码 dump($rep);}/** * CURL发送Content-type为application/json的HTTP/HTTPS请求 * @param $url * @param $data */private function _post($url, $data) { $headers = array( "content-type: application/json;charset=UTF-8",//设置请求头 请求的内容格式,编码 "Accept: application/json", //Accept字段头确定客户端可以接收的媒体类型 "Cache-Control: no-cache", "Pragma: no-cache", ); $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_TIMEOUT, 60); //设置超时 if(0 === strpos(strtolower($url), 'https')) { //https请求 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); //对认证证书来源的检查 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); //从证书中检查SSL加密算法是否存在 } curl_setopt( $ch, CURLOPT_POST, true); curl_setopt( $ch, CURLOPT_POSTFIELDS, $data); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true); curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers ); $resp = curl_exec ( $ch ); curl_close ( $ch ); return $resp;}
1 0
- php curl扩展发送https post请求
- PHP CURL 发送HTTPS POST请求
- PHP CURL发送POST请求
- php CURL 发送get,post请求
- php curl 发送post/get请求
- php使用curl发送post请求
- PHP CURL HTTPS POST
- PHP CURL HTTPS POST
- PHP CURL HTTPS POST
- PHP curl请求https
- https发送post请求
- PHP CURL 发送请求
- php curl发送post请求的注意点
- curl 实现发送Get和Post请求(PHP)
- cURL实现发送Get和Post请求(PHP)
- php通过curl发送get和post请求
- php curl 发送GET,POST请求的函数
- cURL实现发送Get和Post请求(PHP)
- MySql与workbench中文乱码问题
- openssl——sha256算法源码
- java:递归实现输出目录下所有的文件(列出目录下所有的文件)
- CSS盒子模型
- 大顶堆
- php curl扩展发送https post请求
- ife系列之自定义checkbox、radio样式
- DIV中position的5个属性值
- 算法:LeetCode215
- POJ 3183 Stump Removal G++
- 可调用对象
- 增加Android下spinner控件的点击下拉列表自动更新事件并实例应用--USB摄像头在spinner内下拉更新(一)
- Java复习IO之File类
- C语言程序运行后 出现exe已停止工作