欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php curl传值

程序员文章站 2023-12-25 17:14:21
...
利用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)

相关标签: php

上一篇:

下一篇: