php 网页发送post请求

来源:互联网 发布:中国数据安全 编辑:程序博客网 时间:2024/06/07 02:26
 function request_post($url = '', $param = '') {        if (empty($url) || empty($param)) {            return false;        }                $postUrl = $url;        $curlPost = $param;        $ch = curl_init();//初始化curl        curl_setopt($ch, CURLOPT_URL,$postUrl);//抓取指定网页        curl_setopt($ch, CURLOPT_HEADER, 0);//设置header        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上        curl_setopt($ch, CURLOPT_POST, 1);//post提交方式        curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);        $data = curl_exec($ch);//运行curl        curl_close($ch);                return $data;    }



$url = 'http://120.24.59.46:9800/userApi/process_inquiry.html';      //  $post_data['auth']       = '147';        $post_data['order_name']      = 'order my name';        $post_data['order_age'] = '99';        $post_data['disease_des'] = '99_nassssssssssssme';        $post_data['order_gender'] = '男';        $post_data['disease_name'] = 'disease name';        $post_data['disease_photos']    = '/upload/img.jpg,/upload/img.jpg';        $o = "";        foreach ( $post_data as $k => $v )         {             $o.= "$k=" . urlencode( $v ). "&" ;        }        $post_data = substr($o,0,-1);//        $res = aa();        $res = request_post($url, $post_data);echo $res;


0 0