<?php require "vendor/autoload.php"; $url = "http://localhost/book/put-form-page.php"; $data = ["email" => "*****@*****.**", "display_name" => "LornaJane"]; $client = new \GuzzleHttp\Client(); $result = $client->put($url, ["headers" => ["Content-Type" => "application/x-www-form-urlencoded"], "body" => http_build_query($data)]); echo $result->getBody();
/** * Get a read-stream for a file * * @param $path * @return array|bool */ public function readStream($path) { $headers = ['User-Agent' => 'testing/1.0', 'Accept' => 'application/json', 'X-Foo' => ['Bar', 'Baz'], 'custom' => 'cust']; $stream = \GuzzleHttp\Stream\Stream::factory('contents...'); $client = new \GuzzleHttp\Client(['headers' => $headers]); $resource = fopen('a.gif', 'r'); $request = $client->put($this->api_url . 'upload', ['body' => $resource]); prn($client, $request); echo $request->getBody(); exit; $location = $this->applyPathPrefix($path); $this->client->setMethod('PUT'); $this->client->setUri($this->api_url . 'upload'); $this->client->setParameterPost(array_merge($this->auth_param, ['location' => $location])); // $this->client // //->setHeaders(['path: /usr/local....']) // ->setFileUpload('todo.txt','r') // ->setRawData(fopen('todo.txt','r')); $fp = fopen('todo.txt', "r"); $curl = $this->client->getAdapter(); $curl->setCurlOption(CURLOPT_PUT, 1)->setCurlOption(CURLOPT_RETURNTRANSFER, 1)->setCurlOption(CURLOPT_INFILE, $fp)->setCurlOption(CURLOPT_INFILESIZE, filesize('todo.txt')); // prn($curl->setOutputStream($fp)); $response = $this->client->send(); prn($response->getContent(), json_decode($response->getContent())); exit; }
<?php require 'vendor/autoload.php'; $client = new GuzzleHttp\Client(); $id = $_GET['id']; $response = $client->request('GET', 'http://docent.cmi.hro.nl/bootb/restdemo/notes', ['query' => ['id' => $id]]); $json = json_decode($response->getBody()); if ($_POST != null) { $title = $_POST['title']; $body = $_POST['body']; $author = $_POST['author']; $response = $client->put('http://docent.cmi.hro.nl/bootb/restdemo/notes/' . $id, ['json' => ['title' => $title, 'body' => $body, 'author' => $author]]); echo $response->getReasonPhrase(); } ?> <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <link rel="stylesheet" href="css/foundation.css"/> </head> <body> <form method="post"> <div class="row"> <div class="small-3 columns"> <label for="middle-label" class="text-right middle">Title</label> </div> <div class="small-9 columns"> <input type="text" name="title" id="middle-label" value="<?php
<?php require __DIR__ . '/vendor/autoload.php'; $client = new \GuzzleHttp\Client(['base_url' => 'http://localhost:8000', 'defaults' => ['exceptions' => false]]); $book1 = array('title' => 'title - test2 - ' . rand(0, 999), 'description' => 'description - test2 - ' . rand(0, 999), 'owner' => 1); $book2 = array('title' => 'edited 9', 'description' => 'edited 9'); $book3 = array('title' => 'edited 10', 'description' => 'edited 10'); $response1 = $client->post('/api/book', ['body' => json_encode($book1)]); //$response2_1 = $client->get('/api/book/3'); //$response2_2 = $client->get('/api/book/16'); //$response3 = $client->get('/api/book'); $response4 = $client->put('/api/book/30', ['body' => json_encode($book2)]); $response5 = $client->delete('/api/book/33'); $response6 = $client->patch("/api/book/31", ['body' => json_encode($book3)]); echo $response1; echo "\n\n"; //echo $response2_1; //echo $response2_2; //echo $response3; echo $response4; echo "\n\n"; echo $response5; echo "\n\n"; echo $response6; echo "\n\n";
/** * Updates the HTTPcheck $checkid with the given parameters * @param int $checkId * @param string $name * @param string $host * @param string $url * @param string $sendtoemail * @param string $sendtoiphone * @param string $sendtoandroid * @param array $contactids * @return string */ public function updateHTTPCheck($checkId, $name, $host, $url, $sendtoemail, $sendtoiphone, $sendtoandroid, $contactids) { $client = new \GuzzleHttp\Client(['base_uri' => 'https://api.pingdom.com/api/2.0/']); $query = ['name' => $name, 'host' => $host, 'url' => $url, 'sendtoemail' => $sendtoemail, 'sendtoiphone' => $sendtoiphone, 'sendtoandroid' => $sendtoandroid, 'contactids' => implode(",", $contactids), 'use_legacy_notifications' => 'true']; try { $response = $client->put('https://api.pingdom.com/api/2.0/checks/' . $checkId, ['query' => $query, 'auth' => [$this->username, $this->password], 'headers' => ['App-Key' => $this->token]]); $response = json_decode($response->getBody(), true); } catch (\Exception $e) { var_dump($e->getResponse()->getBody()->getContents()); throw $e; } return $response; }