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

php curl传值

WBOY
发布: 2016-06-06 20:13:39
原创
978 人浏览过

利用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)

相关标签:
php
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板