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;

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容