zoukankan      html  css  js  c++  java
  • php 模拟浏览器get和post提交处理

    文件夹test下index.php

    <?php
    header("Content-Type: text/html;charset=gb2312");

    function cUrlGet($url='http://www.ji-meng.com'){
    //初始化
    $ch = curl_init();
    //设置选项,包括URL
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    //执行并获取HTML文档内容
    $output = curl_exec($ch);
    //释放curl句柄
    curl_close($ch);
    return $output;
    }
    function cUrlPost($url='http://www.ji-meng.com',$post_data=array()){
    //$url = "http://localhost/web_services.php";
    //$post_data = array ("username" => "bob","key" => "12345");
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    // post数据
    curl_setopt($ch, CURLOPT_POST, 1);
    // post的变量
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    $output[] = curl_exec($ch);
    $output[]=curl_getinfo($ch);
    curl_close($ch);
    return $output;
    }
    list($output,$info)=cUrlPost('http://localhost/test/post.php',array('username1'=>'boby','key'=>'123456'));
    echo $output;
    echo "<br> ";
    foreach ($info as $name=>$key){
    echo "$name===$key<br> ";
    }

    test文件夹下post.php文件

    <?php
    header("Content-Type: text/html;charset=gb2312");

    echo "good! your post:<br>";

    foreach ($_POST as $item=>$key){
    echo "'$item'=".$key."<br> ";
    }
    ?>

  • 相关阅读:
    WebSocket面试题
    面试题、四
    面试题、三
    面试题、二
    面试题、一
    vue 使用localstorage实现面包屑
    flutter,SliverPersistentHeader实现Tab顶部吸附固定效果
    对flutter中,ExpsionPanel的简单改造
    node.js学习笔记
    PHP和Redis实现在高并发下的抢购及秒杀功能示例详解
  • 原文地址:https://www.cnblogs.com/lykouyi/p/5757083.html
Copyright © 2011-2022 走看看