当前位置:Gxlcms > PHP教程 > phpcurl传值

phpcurl传值

时间:2021-07-01 10:21:17 帮助过:4人阅读

利用curl给你接口传递参数 为什么一直是空的 代码如下:

       $userAccounts = $_POST['userAccounts'];
       $userPassword = md5($_POST['userPassword']);

       if($userAccounts == "" || $userPassword == "")
       {
           echo "请将数据填写完整";
       }else
       {
           $url = 'http://192.168.1.135:9999/MJS/user/userRegisterSign'; 
           $data = array(
               'userAccounts' => $userAccounts,
               'userPassword' => $userPassword
               ); 

           $json_data = postData($url, $data);   
       }
       
       function postData($url, $data)     
{     
    $ch = curl_init();     
    $timeout = 300;      
    curl_setopt($ch, CURLOPT_URL, $url);    
    curl_setopt($ch, CURLOPT_POST, true);     
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);     
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);     
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);     
    $handles = curl_exec($ch);     
    curl_close($ch);     
   /* return $handles;*/     
}      

回复内容:

利用curl给你接口传递参数 为什么一直是空的 代码如下:

       $userAccounts = $_POST['userAccounts'];
       $userPassword = md5($_POST['userPassword']);

       if($userAccounts == "" || $userPassword == "")
       {
           echo "请将数据填写完整";
       }else
       {
           $url = 'http://192.168.1.135:9999/MJS/user/userRegisterSign'; 
           $data = array(
               'userAccounts' => $userAccounts,
               'userPassword' => $userPassword
               ); 

           $json_data = postData($url, $data);   
       }
       
       function postData($url, $data)     
{     
    $ch = curl_init();     
    $timeout = 300;      
    curl_setopt($ch, CURLOPT_URL, $url);    
    curl_setopt($ch, CURLOPT_POST, true);     
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);     
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);     
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);     
    $handles = curl_exec($ch);     
    curl_close($ch);     
   /* return $handles;*/     
}      

http_build_query($data)

人气教程排行