继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

php.curl方式发送post报文

慕标5832272
关注TA
已关注
手记 1263
粉丝 233
获赞 1008
/**
 * 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


打开App,阅读手记
1人推荐
发表评论
随时随地看视频慕课网APP