Coder Social home page Coder Social logo

mclient's Introduction

mClient

PHP Curl Class. Require php >= 7.4

Installation

composer require mehmetbeyhz/mclient:dev-master

GET

<?php 
try{
    $r = Request::get('https://api.github.com/users/mehmetbeyhz')
        ->addCurlOptions(CURLOPT_USERAGENT,'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36')
        ->execute()
        ->getResponse();
    print_r($r);
}catch (Exception $e)
{
    echo $e->getMessage();
}

Request Details

<?php 
try{
    $r = Request::get('https://api.github.com/users/mehmetbeyhz')->execute();
    print_r($r->getResponse()); // Direct Response
    print_r($r->getHeaderLine('http_code')); // response headers key
    print_r($r->getResponseHeaders()); // response headers as array
    print_r($r->getCookies()); // key1=value1; key2=value2; 
    print_r($r->getCookies('key1')); // value1
}catch (Exception $e)
{
    echo $e->getMessage();
}

POST

<?php 
try{
    $r = Request::post('https://api.example.com/login')
        ->addPost('username','mt.ks')
        ->addPost('password','123456')
        ->addCurlOptions(CURLOPT_RETURNTRANSFER,false)
        // ->setProxy('proxyUser:[email protected]:8080')
        // ->setJsonPost(true) :: format => {"username":"mt.ks","password":"123456"}
        ->execute()
        // ->getDecodedResponse(true)  => true : as Array, false : as Object
        ->getResponse(); // direct page response
    print_r($r);
}catch (Exception $e)
{
    echo $e->getMessage();
}

MULTI CURL

<?php 
$multiCurl = new MultiRequest();


$multiCurl->add(Request::get("https://jsonplaceholder.typicode.com/todos/1")
    ->setUserAgent("my useragent")
);

$multiCurl->add(Request::get("https://jsonplaceholder.typicode.com/todos/2")
    ->setUserAgent("my useragent")
);

$multiCurl->add(Request::get("https://jsonplaceholder.typicode.com/todos/3")
    ->setUserAgent("my useragent")
    ->setIdentifierParams(['client' => 1])
);

$multiCurl->add(Request::get("https://jsonplaceholder.typicode.com/todos/4")
    ->setUserAgent("my useragent")
    ->setIdentifierParams(['clientId' => 80])
);


foreach ($multiCurl->execute() as $v) {
    $v->getResponseText();
    $v->getDecodedResponse(false);
    $v->getIdentifierParams();
    $v->getHeader('http_status');
    $v->getHeaders();
    $v->getCookies()->getCookie();
    $v->getCookies()->getCookie('sessionID');
    $v->getRequest()->getRequestUri();
}

mclient's People

Contributors

mt-ks avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

thaivanan

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.