RE: How to execute a HTTP POST Using PHP CURL?

How to execute a HTTP POST Using PHP CURL?

dip Team Leader Asked on February 11, 2017 in PHP.
Add Comment
1 Answers



<?php 
 $url = 'http://domainname.com/getPost.php'; 
 $fields = array(
 'name' => urlencode($_POST['name']),
 'email' => urlencode($_POST['email']),
 'phone' => urlencode($_POST['phone'])
 );
 foreach($fields as $key=>$value)
 { $fields_string .= $key.'='.$value.'&'; } 
 rtrim($fields_string, '&'); 
//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($fields)); 
 curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string); 
//execute post 
 $result = curl_exec($ch); 
//close connection 
 curl_close($ch);


?>


Junior Developer Answered on April 4, 2017.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.