首页 >后端开发 >php教程 >php curl传值

php curl传值

WBOY
WBOY原创
2016-06-06 20:13:39977浏览

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

<code>       $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;*/     
}      </code>

回复内容:

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

<code>       $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;*/     
}      </code>

http_build_query($data)

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn