yii\httpclient\Request::setUrl PHP Method

setUrl() public method

Sets target URL.
public setUrl ( string | array $url )
$url string | array use a string to represent a URL (e.g. `http://some-domain.com`, `item/list`), or an array to represent a URL with query parameters (e.g. `['item/list', 'param1' => 'value1']`).
    public function setUrl($url)
    {
        $this->_url = $url;
        $this->_fullUrl = null;
        return $this;
    }

Usage Example

 /**
  * @inheritdoc
  */
 public function format(Request $request)
 {
     $data = (array) $request->getData();
     $content = http_build_query($data, '', '&', $this->encodingType);
     if (strcasecmp('get', $request->getMethod()) === 0) {
         if (!empty($content)) {
             $url = $request->getUrl();
             $url .= strpos($url, '?') === false ? '?' : '&';
             $url .= $content;
             $request->setUrl($url);
         }
         return $request;
     }
     $request->getHeaders()->set('Content-Type', 'application/x-www-form-urlencoded');
     $request->setContent($content);
     return $request;
 }