Skip to content

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

Notifications You must be signed in to change notification settings

VeshkinDima/http-request

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Http Request

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

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

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

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

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

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

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

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

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

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

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

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

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published