How to use TrustedRedirectResponse()? I have used the following code on submit of a form to first send the form contents via guzzle and then redirect the form.  I get the error 

Error: Call to undefined function TrustedRedirectResponse()


this is my code:

use Drupal\Core\Routing\TrustedRedirectResponse;

function mymodule_submit(&amp;$form, FormStateInterface $form_state){
$url="xyz.com";
$post_data=array("color"=&gt;"red");

$client = \Drupal::httpClient();
  $response = $client-&gt;request('POST', $url, [
    'headers' =&gt; ['Content-Type' =&gt; 'application/x-www-form-urlencoded'],
     'verify'=&gt;false,
    'form_params' =&gt; $post_data,

     ]);
    $status = $response-&gt;getStatusCode();

    $response = TrustedRedirectResponse(Url::fromUri($url));
    $form_state-&gt;setResponse($response);
}


I have two questions - how can I avoid the error , and is the order of getting the guzzle response and then getting the redirect response the correct order?
Your order seems correct, you need to instanciate a new TrustedRedirectResponse object like:

$response = new TrustedRedirectResponse($url_string);