PHP - CURL POST

CURL POST

$post_data_arr = [ 'f_name' => 'First', 'l_name' => 'Last', ]; $url = 'http://example.com'; $curl = curl_init($url); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data_arr); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($curl); curl_close($curl); print_r($response);

CURL POST with authentication

$url = 'http://example.com'; $username = "username"; $password = "password"; $curl = curl_init($url); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_TIMEOUT, 2); curl_setopt($curl, CURLOPT_USERPWD, "$username:$password"); curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data_arr); $response = curl_exec($curl); curl_close($curl); print_r($response);

Comments

Popular posts from this blog