コード例 #1
0
 /**
  * Manipulate Http Request
  *
  * @param iHttpRequest $request
  */
 function withHttpRequest(iHttpRequest $request)
 {
     $params = \Poirot\Std\iterator_to_array($this);
     $body = http_build_query($params, null, '&');
     $request->setBody($body);
     $request->getHeaders()->set(HeaderFactory::factory('Content-Type', 'application/x-www-form-urlencoded'));
 }
コード例 #2
0
ファイル: BJsonPlugin.php プロジェクト: phPoirot/HttpAgent
 /**
  * Manipulate Http Request
  *
  * @param iHttpRequest $request
  */
 function withHttpRequest(iHttpRequest $request)
 {
     $params = \Poirot\Std\iterator_to_array($this);
     $body = json_encode($params);
     $request->setBody($body);
     $request->getHeaders()->set(HeaderFactory::factory('Content-Type', 'application/json'));
 }
コード例 #3
0
 /**
  * @param HttpSocketTransporter $transporter
  * @param iHttpRequest          $request
  *
  * @return mixed
  */
 function __invoke($transporter = null, $request = null)
 {
     # Header Content-Length:
     /**
      * Http Messages With Body Should be with Content-Length
      * !! without this post requests always not working
      * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.4
      * @see https://issues.apache.org/jira/browse/TS-2902
      */
     $body = $request->getBody();
     $length = false;
     if ($body) {
         if ($body instanceof iStreamable) {
             $length = $body->getSize();
         } else {
             $length = strlen($body);
         }
     }
     if ($length !== false) {
         if (!$request->getHeaders()->has('Content-Length')) {
             $request->getHeaders()->set(HeaderFactory::factory('Content-Length', (string) $length));
         }
     }
 }