亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

php curl uses post to send data

Use post to send data

What if we want to send POST data? We need to use curl to help us send data.

Following the steps, we customized a function named: post. Two parameters need to be passed in to the post method:

1. The requested URL address

2. The data sent

The data sent are all arrays, with key values Just use the POST method to send the correct form to the specified interface address.

We only need to combine the "15.1 curl usage steps" to complete the corresponding code.

When developing a WeChat public account to create a custom menu, you need to use the POST method to send custom menu data to WeChat's custom menu interface.

Post's custom function, the entire code is as follows:

<?php
function post($url, $data) {

   //初使化init方法
   $ch = curl_init();

   //指定URL
   curl_setopt($ch, CURLOPT_URL, $url);

   //設(shè)定請(qǐng)求后返回結(jié)果
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

   //聲明使用POST方式來進(jìn)行發(fā)送
   curl_setopt($ch, CURLOPT_POST, 1);

   //發(fā)送什么數(shù)據(jù)呢
   curl_setopt($ch, CURLOPT_POSTFIELDS, $data);


   //忽略證書
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

   //忽略header頭信息
   curl_setopt($ch, CURLOPT_HEADER, 0);

   //設(shè)置超時(shí)時(shí)間
   curl_setopt($ch, CURLOPT_TIMEOUT, 10);

   //發(fā)送請(qǐng)求
   $output = curl_exec($ch);

   //關(guān)閉curl
   curl_close($ch);

   //返回?cái)?shù)據(jù)
   return $output;
}
?>

In the future, the WeChat public platform or other third-party API systems will be called. They need to use the POST method when asking you to send data.
When you need to use POST to send data, you only need to adjust the post method.


Continuing Learning
||
<?php function post($url, $data) { //初使化init方法 $ch = curl_init(); //指定URL curl_setopt($ch, CURLOPT_URL, $url); //設(shè)定請(qǐng)求后返回結(jié)果 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //聲明使用POST方式來進(jìn)行發(fā)送 curl_setopt($ch, CURLOPT_POST, 1); //發(fā)送什么數(shù)據(jù)呢 curl_setopt($ch, CURLOPT_POSTFIELDS, $data); //忽略證書 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //忽略header頭信息 curl_setopt($ch, CURLOPT_HEADER, 0); //設(shè)置超時(shí)時(shí)間 curl_setopt($ch, CURLOPT_TIMEOUT, 10); //發(fā)送請(qǐng)求 $output = curl_exec($ch); //關(guān)閉curl curl_close($ch); //返回?cái)?shù)據(jù) return $output; } ?>
submitReset Code