<?php
/**
* Created by PhpStorm.
* User: 18110
* Date: 2018/12/14
* Time: 18:47
*/
class Curl
{
/**
* post请求
* @param $url
* @param array $post_data
* @param string $msg
* @return mixed
*/
public function requestPost($url , $post_data = array() , $msg = ''){
// 1. 初始化一个cURL会话
$ch = curl_init();
// 2. 设置请求选项, 包括具体的url
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// 设置请求为post类型
curl_setopt($ch, CURLOPT_POST, 1);
// 添加post数据到请求中
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_HEADER, 0);
// 3. 执行一个cURL会话并且获取相关回复
$response = curl_exec($ch);
//$response = json_decode($response,true);
if ($response === FALSE) {
if ($msg == ''){
log
PHP curl类库(post、get、json)请求
最新推荐文章于 2021-12-27 16:41:01 发布