curl post请求 , postman 模拟请求 , 在线测试工具模拟请求

1、curl发送post 请求

 function curl_post($url = '', $param = '') {
        if (empty($url) || empty($param)) {
            return false;
        }
        $postUrl = $url;
        $curlPost = $param;
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,$postUrl);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
        $data = curl_exec($ch);
        curl_close($ch);
        return $data;
    }

    function testAction(){
        $url = '';
        $post_data['appKey']      = '';
        $post_data['regionId']    = '';
        $post_data['token']       = '';
        $post_data['sign']    = '';

        $o = "";
        foreach ( $post_data as $k => $v )
        {
            $o.= "$k=" . urlencode( $v ). "&" ;
        }
        $post_data = substr($o,0,-1);
        $res = $this->curl_post($url, $post_data);
        print_r($res);

    }

2、postman模拟post请求

3、还可以直接在网上搜索在线测试工具,模拟post请求,填入对应的参数即可

猜你喜欢

转载自blog.csdn.net/bianb123/article/details/81532672