1.php.ini
- always_populate_raw_post_data = -1
复制代码
2.app/common.php
加入
- function curls($url, $data_string) {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- 'X-AjaxPro-Method:ShowList',
- 'Content-Type: application/json; charset=utf-8',
- 'Content-Length: ' . strlen($data_string))
- );
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
- $data = curl_exec($ch);
- curl_close($ch);
- return $data;
- }
复制代码
3.在Controller 中使用发送
- public function post_raw()
- {
- $url = "http://www.xmspace.net";
- $data = array('discuz维护','app定制开发','专业企业服务器运维','小程序定制开发','企业互联网架构咨询');
- $info = curls($url,json_encode($data));
- var_dump($info);
- }
复制代码
|