Thinkphp POST采用Raw方式发送
1.php.inialways_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);
}
页:
[1]