Its Importance (make curl request):
Sometimes we need make curl request with custom headers. It is generally used to make connection to an api which expect custom headers. SO I am now describing how to make curl request.
Step 01: First you need to initialize your curl request to make curl request.
$curl = curl_init();
Step 02 : Add curl option array generally your request body here. You also set custom header here in CURLOPT_HTTPHEADER key.
curl_setopt_array($curl, array( CURLOPT_URL => "https://yourrequesturl.com", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => "{ \n\t\"CurrencyCode\":\"949\", \n\t\"OrderId\":$order_id, \n\t\"BaseAmount\":$amount, \n\t\"SuccessUrl\":\".$success_url.\", \n\t\"FailUrl\":\".$fail_url.\", \n\t\"PaymentMethodCode\": \"CC\", \n\t\"Ip\": \".$ip.\"\n}", CURLOPT_HTTPHEADER => array( "AppId: some app id", "AppSecret: some app secret", "Content-Type: application/json" ), ));
Step 03: Then execute curl request.
$response = curl_exec($curl); $err = curl_error($curl); curl_close($curl);
You can see the php site documentation