ITPub博客

首页 > IT职业 > IT图书 > php.curl方式发送post报文

php.curl方式发送post报文

IT图书 作者:micromad 时间:2021-09-09 10:06:41 0 删除 编辑
/**
 * curl方式发送post报文
 * $remoteServer 请求地址
 * $postData post报文内容
 * $userAgent用户属性
 * return 返回报文
 */private function _curlRequest($remoteServer, $postData){
    Log::write('发送post报文:址:'.$remoteServer , Log::INFO);
    Log::write('发送post报文:内容:'.json_encode($postData) , Log::INFO);

    $data_string = json_encode($postData);

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_URL, $remoteServer);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(            'Content-Type: application/json',            'Content-Length: ' . strlen($data_string))
    );
    $result = urldecode(curl_exec($ch));
    curl_close($ch);    return $data = empty($result) ? array() : json_decode($result, true);
}

作者:virhuiai
链接:https://www.jianshu.com/p/d5e83023f8e4


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2763/viewspace-2816580/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-08-16

  • 博文量
    75
  • 访问量
    574