Home > Article > Backend Development > Curl post request function
/**3 * PHP Crul library simulates Post submission to Alipay gateway
4 * If you use Crul, you need to change the settings of your php.ini file, find php_curl.dll and remove the ";" in front of it.
5 * return $data
6*/
7 function post($gateway,$req_data) {
8 $ch = curl_init();
9 curl_setopt($ch, CURLOPT_URL, $gateway); //Configure the gateway address
10 curl_setopt($ch, CURLOPT_HEADER, 0); //Filter
HTTP header
11 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
12 curl_setopt($ch, CURLOPT_POST, 1); //Set post submission
13 curl_setopt($ch, CURLOPT_POSTFIELDS, $req_data); //post transfer data
14 $data = curl_exec($ch);
15 curl_close($ch);
16 return $data;
17}
|