无限星辰工作室-客户无限互联网动力之源

标题: Thinkphp POST采用Raw方式发送 [打印本页]

作者: crx349    时间: 2019-3-27 15:45
标题: Thinkphp POST采用Raw方式发送
1.php.ini
  1. always_populate_raw_post_data = -1
复制代码

2.app/common.php
加入
  1. function curls($url, $data_string) {
  2. $ch = curl_init();
  3. curl_setopt($ch, CURLOPT_URL, $url);
  4. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

  5. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  6. 'X-AjaxPro-Method:ShowList',
  7. 'Content-Type: application/json; charset=utf-8',
  8. 'Content-Length: ' . strlen($data_string))
  9. );
  10. curl_setopt($ch, CURLOPT_POST, 1);
  11. curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
  12. $data = curl_exec($ch);
  13. curl_close($ch);
  14. return $data;
  15. }
复制代码


3.在Controller 中使用发送
  1. public function post_raw()

  2. {
  3.   $url = "http://www.xmspace.net";
  4.    $data = array('discuz维护','app定制开发','专业企业服务器运维','小程序定制开发','企业互联网架构咨询');
  5.  $info = curls($url,json_encode($data));
  6.   var_dump($info);

  7. }
复制代码







欢迎光临 无限星辰工作室-客户无限互联网动力之源 (https://www.xmspace.net/) Powered by Discuz! X3.4