Make a post request usign CURL and PHP

  1.  
  2. $fields = array(
  3.         ‘a’=>‘1’,
  4.         ‘b’=>‘2’,
  5.         ‘c’=>‘3’,
  6.         ‘d’=>‘4’
  7. );
  8. $ch = curl_init();
  9. curl_setopt($ch,CURLOPT_URL, ‘http://mysite.com’);
  10. curl_setopt($ch,CURLOPT_POST, count($fields));
  11. curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($fields) );
  12. curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
  13. $result = curl_exec($ch);
  14. curl_close($ch);
  15.  

Leave a Reply

Your email address will not be published. Required fields are marked *