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; }
  • 相关阅读:
    一、HTML基础学习
    算法之求正整数的二进制
    JavaScript ajax返回状态
    ajax实现异步校验
    比较喜欢的一种求阶乘的方法:用递归求阶乘
    java中自定义异常类
    我对多态的理解
    包装类和基本类型区别?(integer和int取值范围一样大)
    JAVA中默认的编码方式
    抽象类和接口的区别
  • 原文地址:https://www.cnblogs.com/whoamme/p/2662187.html
Copyright © 2011-2022 走看看