PHP用curl发送请求

/**

* 发送请求

* @return bool|string 返回false或者代理任务id

*/

public function send()

{

    if ($this->through) {

        return false;

    }

    $curl = curl_init();

    curl_setopt($curl, CURLOPT_URL, $this->proxyUrl);

    curl_setopt($curl, CURLOPT_HEADER, 0);

    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

    curl_setopt($curl, CURLOPT_POST, 1);

    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);

    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

    curl_setopt($curl, CURLOPT_TIMEOUT, 3);

    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);

    curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query([

        'data' => base64_encode(json_encode($this->postData))

    ]));

    $ret = curl_exec($curl);

    curl_close($curl);

    if ($ret && ($ret = @json_decode($ret))) {

        if ($ret->code == 0) {

            return $ret->data->task_id;

        }

        $this->errMsg = $ret->message;

    } else {

        $this->errMsg = '服务异常,请检查网络!';

    }

    return false;

}

你可能感兴趣的:(PHP用curl发送请求)