<?php //curl类 class Curl { function Curl(){ return true; } function execute($method, $url, $fields='', $userAgent='', $httpHeaders='', $username='', $password=''){ $ch = Curl::create(); if(false === $ch){ return false; } if(is_string($url) && strlen($url)){ $ret = curl_setopt($ch, CURLOPT_URL, $url); }else{ return false; } //是否显示头部信息 curl_setopt($ch, CURLOPT_HEADER, false); // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); if($username != ''){ curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password); } $method = strtolower($method); if('post' == $method){ curl_setopt($ch, CURLOPT_POST, true); if(is_array($fields)){ $sets = array(); foreach ($fields AS $key => $val){ $sets[] = $key . '=' . urlencode($val); } $fields = implode('&',$sets); } curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); }else if('put' == $method){ curl_setopt($ch, CURLOPT_PUT, true); }
GET usage:
$curl = new Curl(); $curl->get('http://www.XXX.com/');
POST usage:
$curl = new Curl(); $curl->get('http://www.XXX.com/', 'p=1&time=0');
All resources on this site are contributed by netizens or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this site are for learning reference only. Please do not use them for commercial purposes. Otherwise, you will be responsible for all consequences! If there is any infringement, please contact us to delete it. Contact information: admin@php.cn
Related Article
21 May 2017
cURL can use the syntax of a URL to simulate a browser to transfer data. Because it is an analog browser, it supports a variety of protocols, such as FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT, FILE and LDAP, etc., including:
23 Dec 2016
This article mainly introduces the PHP encapsulated CURL extension class, and analyzes related techniques such as sending posts, get requests and operating cookies based on curl. It has certain reference value. Friends in need can refer to it.
29 Dec 2017
This article mainly introduces the powerful PHP POST data submission class in detail. The code is concise and has certain reference value. Interested friends can refer to it. I hope to be helpful.
13 Jul 2016
Example of using php curl wrapper class. Examples of using the php curl package class. Before using the function, we need to open the php curl module (libeay32.dll, ssleay32.dll, php5ts.dll, php_curl.dll). Steps to open the php curl function library 1). Remove
Hot Tools
PHP library for dependency injection containers
PHP library for dependency injection containers
A collection of 50 excellent classic PHP algorithms
Classic PHP algorithm, learn excellent ideas and expand your thinking
Small PHP library for optimizing images
Small PHP library for optimizing images