php 常用post请求

作者: cayman 分类: 未分类 发布时间: 2021-08-02 11:25
public function postData($url, $data, $timeout = 300)
{
    $headers = array(
        "Cache-Control: no-cache",
        "Content-Type: application/x-www-form-urlencoded"
    );
    $curl = curl_init();
    curl_setopt_array($curl, array(
        CURLOPT_URL => $url,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => "",
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => $timeout,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS => $data,
        CURLOPT_HTTPHEADER => $headers,
        CURLOPT_SSL_VERIFYPEER=>false

    ));
    $response = curl_exec($curl);
    $err = curl_error($curl);
    curl_close($curl);
    return $response;
}

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注