예제 #1
0
파일: Push.php 프로젝트: blar/push
 /**
  * @return \Blar\Http\HttpRequest
  */
 public function createRequest()
 {
     $request = new HttpRequest();
     $request->setMethod('POST');
     $request->setUrl($this->getHubUrl());
     return $request;
 }
예제 #2
0
 /**
  * @return \Blar\Http\HttpRequest
  */
 public function createRequest()
 {
     $request = new HttpRequest();
     $request->setMethod('POST');
     $request->getHeaders()->set('Content-Type', 'application/xml');
     $request->getHeaders()->set('Accept', 'application/xml, text/xml');
     return $request;
 }
예제 #3
0
 public function testDeleteRequestWithBody()
 {
     $request = new HttpRequest();
     $request->setMethod('DELETE');
     $request->setUrl('http://httpbin.org/delete?foo=23&bar=42');
     $request->setBody(array('foo' => 23, 'bar' => 42));
     $request->on('responseReceived', function ($event) {
         $response = $event->getTarget();
         if ($response->getHeaders()->get('Content-Type')->getMimeType() == 'application/json') {
             $decoded = json_decode($response->getBody());
             $response->setBody($decoded);
         }
     });
     $response = $request->send();
     $headers = $response->getHeaders();
     $this->assertEquals('HTTP/1.1 200 OK', $headers->get('Status'));
     $this->assertEquals('application/json', $headers->get('Content-Type')->getMimeType());
     $body = $response->getBody();
     $this->assertEquals(23, $body->args->foo);
     $this->assertEquals(42, $body->args->bar);
     $this->assertEquals(23, $body->form->foo);
     $this->assertEquals(42, $body->form->bar);
 }
예제 #4
0
 /**
  * @param string $methodName Method name.
  * @param array $arguments Arguments.
  * @return Blar\Http\HttpRequest
  */
 public function createRequest($methodName, array $arguments = array())
 {
     if (!$this->getWebserviceDescription()->has($methodName)) {
         throw new Exception(sprintf('Method "%s" not found', $methodName), 404);
     }
     $method = $this->getWebserviceDescription()->get($methodName);
     $method->getParameters()->setValues($this->getDefaultArguments());
     $method->getParameters()->setValues($arguments);
     $request = new HttpRequest();
     $request->setMethod($method->getMethod());
     $this->prepareRequest($request, $method);
     $event = new Event();
     $event->setTarget($request);
     $this->getEmitter()->fireEvent('requestCreated', $event);
     return $request;
 }