zoukankan      html  css  js  c++  java
  • file_get_contents模拟表单(POST/GET方式提交)

    $name         = 'yangheping';
    $pwd          = 'yhpadmin';
    $phone        = '158********';
    $content      = '测试POST\GET发送方式';
    
    //组合提交URL以及参数 (GET方式)
    //$http       = 'http://www.ceshi.cc/php/post.php'.'?name='.$name.'&pwd='.$pwd.'&dest='.$phone.'&content='.$content;
    //$result     = get_to($http);
    
    
    //组合提交URL以及参数 (POST方式)
    $http       = 'http://www.ceshi.cc/php/post.php';
    $var        = 'name='.$name.'&pwd='.$pwd.'&dest='.$phone.'&content='.$content;

    $result = post_to($var, $http);

    /** * 提交的GET接口 * @param string $http 接口地址 * @return int */ /* function get_to($http) { $context = array( 'http'=>array( 'timeout'=> 20, 'method' => 'GET', 'header' => "Content-type: application/x-www-form-urlencoded\r\n", ) ); $xcontext = stream_context_create($context); $ret = @file_get_contents($http, false, $xcontext); //返回 return $ret; } */ /** * 提交的post接口 * @param array $vars 数据 * @param string $http 接口地址 * @return int */ function post_to($vars, $http){ $context = array( 'http'=>array( 'timeout'=> 20, 'method' => 'POST', 'header' => "Content-type: application/x-www-form-urlencoded\r\n" . "Content-length: " . strlen($vars)."\r\n", 'content'=> $vars ) ); $xcontext = stream_context_create($context); $ret = @file_get_contents($http,false,$xcontext); //返回 return $ret; }
  • 相关阅读:
    原型模式
    简单工厂模式与工厂方法模式
    监听器 Listener
    代理模式
    装饰模式
    软件设计的原则
    事务的特性和隔离级别
    JDBC事务(三)ThreadLocal绑定Connection
    JDBC事务(二)转账示例
    JDBC事务(一)
  • 原文地址:https://www.cnblogs.com/whoamme/p/2662187.html
Copyright © 2011-2022 走看看