Post form to external URL I need to POST the data in a form to an external URL.

In Drupal 7, you would use

$form['#action'] = url('http://example.com', array('external' =&gt; true));


Or maybe this was for GET. Anyway... in Drupal 8, this does not work. I have tried editing the submitForm method:

public function submitForm(array &amp;$form, FormStateInterface $form_state) {
    $response = new TrustedRedirectResponse('http://example.com');
    $response-&gt;send();
}


This works, however I have not found a way to submit the values of the form along with the request. I looked at the httpClient class, but it seems that is for sending/requesting data only and does not redirect the user.

Hope someone can help me out. If it comes down to it I am fine with using GET instead.
$form['#action'] works the same, Drupal 7 or Drupal 8. It needs a string, which is what url() returns in Drupal 7. The reason why url() is normally used is because the code has a relative path for a routing item, such as in url('comment/reply/'. $edit['nid']).  

In Drupal 8, for example, the Comment module uses the following code.

$form['#action'] = $this-&gt;url('comment.reply', array('entity_type' =&gt; $entity-&gt;getEntityTypeId(), 'entity' =&gt; $entity-&gt;id(), 'field_name' =&gt; $field_name));


UrlGeneratorTrait::url(), the method called in that code, still returns a string, not an object. Also in this case, UrlGeneratorTrait::url() is used because the code has a route name (comment.reply) and it wants to get the URL for that route.

The following code works for Drupal 7 and Drupal 8.

$form['#action'] = 'http://example.com';