thinkphp ,php post发送json请求,就收post请求
发送方的代码如下
- <?php
- namespace Api\Controller;
- use Think\Controller;
- class IndexController extends Controller
- {
- public function send()
- {
- ini_set("error_reporting","E_ALL & ~E_NOTICE");
- $obj->phonenum = '1111111';
- $data = json_encode($obj);
- $url = "http://www.****.cn/Api/Sync/phonenum";
- $res = $this->http_request($url, $data);
- echo $res;
- }
- // HTTP请求(支持HTTP/HTTPS,支持GET/POST)
- function http_request($url, $data = null)
- {
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
- if (! empty($data)) {
- curl_setopt($curl, CURLOPT_POST, 1);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
- }
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
- $output = curl_exec($curl);
- curl_close($curl);
- return $output;
- }
- }