首頁 >後端開發 >php教程 >php curl传值

php curl传值

WBOY
WBOY原創
2016-06-06 20:13:39975瀏覽

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