Post form to external URL
$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';