php模拟post提交

<?php
    $url = "xxxxx";
    
    // 用户名
    $loginName = '';
    
    // 密码
    $pwd = '';
    
    // service
    $serviceName = 'IDNameCheck';
    
    $arr = array ( 
        "loginName" => $loginName, 
        "pwd" => $pwd,
        "serviceName" => $serviceName, 
        "param" => array (
            // 姓名
            "name" => 'xxx',
            // 身份证号
            "idCard" => 'xxxxxxxxxxxxxxxxxxx'
        )
    );
    
    $post_data = json_encode($arr, JSON_UNESCAPED_UNICODE);
    
    $response = doRequest($url, $post_data);
    echo urldecode($response);
    
    function doRequest($url, $post_data) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        $data = curl_exec($ch);
        curl_close($ch);
        return $data;
    }
?>

 

posted @ 2017-07-06 15:13  幸福安康  阅读(169)  评论(0编辑  收藏  举报