第一种:file_get_contents来模拟post

function file_get_contents_post($url, $post){
    $options = array(
             'http'=> array(
             'method'=>'POST',
             'content'=> http_build_query($post),
              ),
     );
    $result = file_get_contents($url,false, stream_context_create($options));
    return $result;
 }

$data = file_get_contents_post("http://xxx.xxx.xx/post.php", 
array('name'=>'caiknife','email'=>'1178350505@qq.com'));
var_dump($data);

第二种curl模拟post

function curl_post($url, $post){
    $options = array(
        CURLOPT_RETURNTRANSFER =>true,
        CURLOPT_HEADER =>false,
        CURLOPT_POST =>true,
        CURLOPT_POSTFIELDS => $post,
    );
    $ch = curl_init($url);
    curl_setopt_array($ch, $options);
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
}

$data = curl_post("http://www.a.com/post/post.php", 
array('name'=>'caiknife','email'=>'caiknife#gmail.com'));
var_dump($data);
最后修改:2020 年 11 月 16 日
如果觉得我的文章对你有用,请随意赞赏