Giter Club home page Giter Club logo

curl_http_client's Introduction

CurlHttpClient

Curl based HTTP Client - Simple but effective OOP wrapper around Curl php lib. It allows sending post/get requests, using proxy, binding to specific IP, storing cookies etc.

Installation

Add CurlHttpClient to your composer.json

{
    "require": {
        "dinke/curl-http-client": "dev-master"
    }
}

Usage

$curl = new \Dinke\CurlHttpClient;

//pretend to be Firefox 19.0 on Mac
$useragent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:19.0) Gecko/20100101 Firefox/19.0";
$curl->setUserAgent($useragent);

//uncomment next two lines if you want to automatically manage cookies
//which will store them to file and send them on each http request
//$cookies_file = "/tmp/cookies.txt";
//$curl->storeCookies($cookies_file);

//Uncomment next line if you want to set credentials for basic http_auth
//$curl->setCredentials($username, $password);

//Uncomment next line if you want to set specific referrer
//$curl->setReferer('http://www.foo.com/referer_url/');

//if you want to send some post data
//form post data array like this one
$post_data = ['login' => 'pera', 'password' => 'joe', 'other_foo_field' => 'foo_value'];
//or like a string: $post_data = 'login=pera&password=joe&other_foo_field=foo_value';

//and send request to http://www.foo.com/login.php. Result page is stored in $html_data string
$html_data = $curl->sendPostData("http://www.foo.com/login.php", $post_data);

//You can also fetch data from somewhere using get method!
//Fetch html from url
$html_data = $curl->fetchUrl("http://www.foo.com/foobar.php?login=pera&password=joe&other_foo_field=foo_value");

//if you have more than one IP on your server,
//you can also bind to specific IP address like ...
//$bind_ip = "192.168.0.1";
//$curl->fetch_url("http://www.foo.com/login.php", $bind_ip);
//$html_data = $curl->sendPostData("http://www.foo.com/login.php", $post_data, $bind_ip);

//and there are many other things you can do like

//use proxy
//$curl->setProxy('http://www.proxyurl.com');

//use proxy auth
//$curl->setProxyAuth('user:pass');

//get http response code for last request
//$http_code = $curl->getHttpResponseCode();

//get last http request duration in sec
//$duration = $curl->get_requestDuration();

curl_http_client's People

Contributors

dinke avatar byjg avatar pherum avatar

Watchers

James Cloos avatar Artem Zinoviev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.