GithubHelp home page GithubHelp logo

shulikov-v / http-request Goto Github PK

View Code? Open in Web Editor NEW

This project forked from garik-/http-request

0.0 2.0 0.0 2.94 MB

Библиотека для простой работы с HTTP протоколом

Home Page: http://habrahabr.ru/post/187164/

PHP 100.00%

http-request's Introduction

Http Request

Библиотека для простой работы с HTTP протоколом, основанная на одноименной библиотеке Kevin Sawicki.

Небольшие примеры

Получение ответа от стороннего сервиса в формате JSON

try {
    $http = \Garik\HttpRequest::get('http://geocode-maps.yandex.ru/1.x/?format=json', array('geocode' => $city))->acceptJson();
    $json = $http->ok() ? json_decode($http->body()) : null;
} catch (\Garik\HttpRequestException $e) {
    exit($e->getMessage());
}

Отправка формы методом POST со своими заголовками

$http = \Garik\HttpRequest::post('http://example.com/')->form(
  array(
    'param1' => 'value',
    'param2' => 'value',
    'file' => '@/home/vasya/attach.txt'
  ))
    ->header(\Garik\HttpRequest::HEADER_USER_AGENT, 'Opera/9.60 (J2ME/MIDP; Opera Mini/4.2.14912/812; U; ru)')
    ->header(\Garik\HttpRequest::HEADER_REFERER, 'http://google.com');

Отправка файла методом PUT

$http = \Garik\HttpRequest::put('http://example.com/')->upload('/home/vasja/attach.txt');

Вывести все заголовки ответа сервера

print_r(\Garik\HttpRequest::head("http://example.com")->headers());

Загрузка файла с сервера

$image = fopen('image.jpg', 'wb');
$loaded = \Garik\HttpRequest::get('http://example.com/file.jpg')->receive($image)->ok(); // boolean

http-request's People

Contributors

garik- avatar

Watchers

James Cloos avatar  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.