protected function prepareRequest(RequestInterface $request, $method, $url, $data, $headers)
    {
        $url = (string) $url;

        // If is GET, we merge data into URL.
        if (is_array($data) && strtoupper($method) === 'GET') {
            $url = new Uri($url);

            foreach ($data as $k => $v) {
                $url->setVar($k, $v);
            }

            $url = (string) $url;
            $data = null;
        }

        // If not GET, convert data to query string.
        if (is_array($data)) {
            $data = UriHelper::buildQuery($data);
        }

        /** @var RequestInterface $request */
        $request->getBody()->write((string) $data);

        $request = $request->withRequestTarget((string) new PsrUri($url))
            ->withMethod($method);

        // Set global headers
        foreach ((array) $this->getOption('headers') as $key => $value) {
            $request = $request->withHeader($key, $value);
        }

        // Override with this method
        foreach ($headers as $key => $value) {
            $request = $request->withHeader($key, $value);
        }

        return $request;
    }
protected function prepareRequest(RequestInterface $request, $method, $url, $data, $headers)
    {
        $url = (string) $url;

        // If is GET, we merge data into URL.
        if (is_array($data) && strtoupper($method) === 'GET') {
            $url = new Uri($url);

            foreach ($data as $k => $v) {
                $url->setVar($k, $v);
            }

            $url = (string) $url;
            $data = null;
        }

        // If not GET, convert data to query string.
        if (is_array($data)) {
            $data = UriHelper::buildQuery($data);
        }

        /** @var RequestInterface $request */
        $request->getBody()->write((string) $data);

        $request = $request->withRequestTarget((string) new PsrUri($url))
            ->withMethod($method);

        // Set global headers
        foreach ((array) $this->getOption('headers') as $key => $value) {
            $request = $request->withHeader($key, $value);
        }

        // Override with this method
        foreach ($headers as $key => $value) {
            $request = $request->withHeader($key, $value);
        }

        return $request;
    }
protected function prepareRequest ( RequestInterface $ request , $ method , $ url , $ data , $ headers ) { $ url = ( string ) $ url ; // If is GET, we merge data into URL. if ( is_array ( $ data ) && strtoupper ( $ method ) === 'GET' ) { $ url = new Uri ( $ url ) ; foreach ( $ data as $ k => $ v ) { $ url -> setVar ( $ k , $ v ) ; } $ url = ( string ) $ url ; $ data = null ; } // If not GET, convert data to query string. if ( is_array ( $ data ) ) { $ data = UriHelper :: buildQuery ( $ data ) ; } /** @var RequestInterface $request */ $ request -> getBody ( ) -> write ( ( string ) $ data ) ; $ request = $ request -> withRequestTarget ( ( string ) new PsrUri ( $ url ) ) -> withMethod ( $ method ) ; // Set global headers foreach ( ( array ) $ this -> getOption ( 'headers' ) as $ key => $ value ) { $ request = $ request -> withHeader ( $ key , $ value ) ; } // Override with this method foreach ( $ headers as $ key => $ value ) { $ request = $ request -> withHeader ( $ key , $ value ) ; } return $ request ; }
Prepare Request object to send request.

@param   RequestInterface $request The Psr Request object.
@param   string           $method  The method type.
@param   string|object    $url     The URL to request, may be string or Uri object.
@param   mixed            $data    The request body data, can be an array of POST data.
@param   array            $headers The headers array.

@return  RequestInterface
@throws \RuntimeException
@throws \InvalidArgumentException
Prepare Request object to send request .