首页 > 技术文章 > Thinkphp POST raw 传值

leaf-cq 2018-03-05 16:51 原文

//在Common/function 添加此函数

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;
}

 

//在Controller 里面直接调用

public function test()

{

  $url = "http://www.xxxx.com";

   $data = array(xxxxxxx);

 $info = curls($url,$data);

  var_dump($info);

}

还不会,有大招,关注下方公众号直接提问就可以了哈

推荐阅读