很多时候,我们在使用php进行编程的时候,都会用到get或者post请求,上次在《 php采集或调用api接口常用函数》的里面,已经提到过了get的使用方法,那么今天就来分享下post 的用法。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | <?php //请输入你的php代码 //$postdata = http_build_query($data); 要发送的数据 $data = array( 'action'=>'getinfo', 'svname'=>'红海行动', 'svsite'=>'ok'); $data = http_build_query($data); //$postdata = http_build_query($data); $options = array( 'http' => array( 'method' => 'POST', 'header' => 'Content-type:application/x-www-form-urlencoded', 'content' => $data //'timeout' => 60 * 60 // 超时时间(单位:s) ) ); $url = "http://www.zhe94.com"; //要请求的网址 $context = stream_context_create($options); //echo $context; $result = file_get_contents($url, false, $context); echo $result; ?> |
转载请保留本文链接:https://www.zhe94.com/134.html