GithubHelp home page GithubHelp logo

borodatych / request Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mashinamashina/request

0.0 1.0 0.0 28 KB

Надстройка над Curl

License: GNU General Public License v3.0

PHP 100.00%

request's Introduction

request

  • request class - PHP надстройка над CURL, упрощающая жизнь разработчику

Самый простой пример:

$request = new request('https://github.com');
$request->send();

echo $request->response;

Методы:

  • request::__construct($url) - устанавливает URL запроса
  • request::set($key, $value) - Устанавливает параметр CURL. Описание параметров
  • request::session($name = false) - Устанавливает имя сессии (Путь сохранения cookie, а не имя PHPSESSID). ! Надо настроить путь: заменить DATA в строке $this->dir = DATA.'/'.$this->name;
  • request::post($data = array()) - устанавливает передаваемые данные и тип запроса в POST
  • request::payload($data) - устанавливает тип запроса POST, данные кодирует в JSON Можно чуть-чуть почитать тут
  • request::send() - отправляет запрос. Возвращает содержимое страницы запроса
  • request::error() - проверяет наличие ошибок. Если их нет возвращает False, иначе описание ошибки
  • request::get_charset() - возвращает кодировку. Метод пытается определить кодировку:
    1. В заголовках
    2. В теле страницы
    3. С момощью mb_detect_encoding()
  • request::dump() - возвращает полное описание запроса

Примеры:

$request = new request('http://google.com');
$request->session('google');
$request->send();

if( $request->error())
{
  echo $request->dump();
  die();
}
$data = array(
  'login' => 'Vasya',
  'passwd' => '12345'
);

$request = new request('http://example.com');
$request->post($data);
$request->send();

echo $request->response;
$data = array(
  'auth' => array(
    'login' => 'Vasya',
    'passwd' => '12345'
  ),
  'order' => array(
    'id' => 1
  )
);

$request = new request('http://example.com');
$request->payload($data);
$request->send();

echo $request->response;

request's People

Contributors

mashinamashina avatar

Watchers

 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.