예제 #1
0
 public function send()
 {
     if (is_null($this->getBody())) {
         $body = null;
     } else {
         $body = new Body();
         $body->append($this->getBody());
     }
     $request = new Request($this->getMethod(), 'https://' . $this->getUrl(), $this->getHeaders(), $body);
     $request->addQuery($this->getQuery());
     $client = new Client();
     $client->enqueue($request)->send();
     $this->response = $client->getResponse();
 }
예제 #2
0
<?php

use http\Client, http\Client\Request;
use http\QueryString;
//$params = new QueryString;
$params["foo"] = "bar";
$params["bar"] = "foo";
$request = new Request("POST", "http://www.google.com");
$request->getBody()->append($params);
$request->setContentType("application/x-www-form-urlencoded");
$client = new Client();
$client->enqueue($request);
$client->send();
$response = $client->getResponse($request);
printf("Sent:\n%s\n\n", $response->getParentMessage());
printf("%s returned '%s'\n%s\n", $response->getTransferInfo("effective_url"), $response->getInfo(), $response->getBody());
?>
 
Sent:
POST http://example.com HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Content-Length: 7
 
bar=foo
 
http://example.com/ returned 'HTTP/1.1 200 OK'
<!doctype html>
<html>
<head>
    <title>Example Domain</title>