title: Laravel 4 make post request from controller to external url with data
body: <p>I am looking for a way to make a post request from a controller to an external url. The data being posted is a php array. The url to recieve is an ecommerce API in an external url. The post has to be done from the controller method. The url should  reply with 'success', 'error', 'failure' or 'trylater' string. I have tried the following with no success:</p>
  
  <pre><code>    return Redirect::to("https://backoffice.host.iveri.com/Lite/Transactions/New/Authorise.aspx", compact($array));
  </code></pre>
  
  <p>I have tried curl too:</p>
  
  <pre><code>    $url = 'https://backoffice.host.iveri.com/Lite/Transactions/New/Authorise.aspx';
      //url-ify the data for the POST
      $fields_string ='';
      foreach($array as $key=&gt;$value) { $fields_string .= $key.'='.$value.'&amp;'; }
      rtrim($fields_string,'&amp; ');
  
      //open connection
      $ch = curl_init();
  
      //set the url, number of POST vars, POST data
      curl_setopt($ch,CURLOPT_URL, $url);
      curl_setopt($ch,CURLOPT_POST, count($array));
      curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
      curl_setopt($ch, CURLOPT_HEADER, 0);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  
      //execute post
      $result = curl_exec($ch);
  
      //close connection
      curl_close($ch);
  </code></pre>
  
  <p>Part of the array being sent is the callbacks that the API uses to responds:</p>
  
  <pre><code>'Lite_Website_Successful_url' =&gt; 'https://mydomain.com/order/'.$order_id,
  'Lite_Website_Fail_url' =&gt; 'https://mydomain.com/checkout/fail',
  'Lite_Website_TryLater_url' =&gt; 'https://mydomain.com/checkout/trylater',
  'Lite_Website_Error_url' =&gt; 'https://mydomain.com/checkout/error'
  </code></pre>
  
  <p>Please let me know how to do a POST request properly with data carried with it to an external url. An ajax post from the controller too would help but I have tried with no success. But I would prefer a laravel php answer more. Thank you.</p>