方法一,用 file_get_contents

function send_post($url, $post_data) {

        //$postdata = http_build_query($post_data);    //把数组转换成key=val&
$options = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type:application/x-www-form-urlencoded',
'content' => $post_data,
'timeout' => 2 * 60 // 超时时间(单位:s)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context); return $result;
}

方法二、

 function send_post2($host,$port,$urlPage,$postData){
// echo str_pad(" ", 256); $errno = '';
$errstr = ''; $length = strlen($postData); $fp = fsockopen($host,$port,$errno,$errstr,120) or exit($errstr."--->".$errno);
//构 造post请求的头
$header = "POST $urlPage HTTP/1.1\r\n";
$header .= "Host:".$host."\r\n";
$header .= "Referer:".$urlPage."\r\n";
$header .= "Content-Type:application/x-www-form-urlencoded\r\n";
$header .= "Content-Length:".$length."\r\n";
$header .= "Connection:Close\r\n\r\n";
//添加post的字符串
$header .= $postData."\r\n"; // echo "1";
// my_flush();
//发送post的数据
fputs($fp, $header);
// echo "2";
// my_flush();
$inheader = 1;
$result = ""; //最终结果 while (!feof($fp)){ $line = fgets($fp,1024); // 去除请求包的头只显示页面 的返回数据 (注意fgets fread($fp,1)最少2个字节起。) // echo $line;
// my_flush();
if($inheader && ($line == "\n" || $line == "\r\n"))
$inheader = 0; if($inheader==0){ $result .= $line; }
}
fclose($fp);
// echo "3";
// my_flush();
return $result; } //刷新缓冲区
function my_flush(){
ob_flush();
flush();
}

调用示例、

$host = "127.0.0.1";
$urlPage = "http://localhost/admin/confirmCode.php";
$port = "80";
$postData = "AAobjid=33$&username1=fff";
echo send_post2($host,$port,$urlPage,$postData) ;
// echo send_post($urlPage,$postData);

php接口post提交方法 。的更多相关文章

  1. php接口post提交方法 (改良版)

    $postData = "reqType=2&caller=15088719619&called=15068722845"; $result = send_post ...

  2. Loadrunner Http接口Get/Post方法性能测试脚本解析

    最近使用LoadRunner 11进行了一次完整的Http WEB接口性能测试,下面介绍下Http接口Get/Post方法性能测试脚本通用编写方法. 1. Http接口性能测试基本流程 首先定义了一个 ...

  3. 详解OJ(Online Judge)中PHP代码的提交方法及要点【举例:ZOJ 1001 (A + B Problem)】

    详解OJ(Online Judge)中PHP代码的提交方法及要点 Introduction of How to submit PHP code to Online Judge Systems  Int ...

  4. C# 索引器,实现IEnumerable接口的GetEnumerator()方法

    当自定义类需要实现索引时,可以在类中实现索引器. 用Table作为例子,Table由多个Row组成,Row由多个Cell组成, 我们需要实现自定义的table[0],row[0] 索引器定义格式为 [ ...

  5. AJAX提交方法(POST)Demon

    AJAX的POST提交方法,本质上来看和GET差不多,有些细小的区别,POST要提交数据时,需要setRequestHeader()方法来提交HTTP头,然后send()方法中提交数据(格式为:&qu ...

  6. 通过实现System.IComparable接口的CompareTo方法对两个类进行比较

    假设现在有一个学生类 class Student { int age; public Student(int age) { this.age = age; } } 要使学生类之间能进行比较,实现Sys ...

  7. ICompare接口、Sort()方法

    1.接口中的方法并不实现具体功能,继承于该接口的类必须实现具体功能. 核心思想:对修改封闭,对扩展开放. 2.Sort()方法: 默认:Sort(内容) 英文:按照首字母顺序排序,首字母相同则看第二个 ...

  8. Java8新特性——接口的默认方法和类方法

    Java8新增了接口的默认方法和类方法: 以前,接口里的方法要求全部是抽象方法,java8以后允许在接口里定义默认方法和类方法: 不同的是: 默认方法可以通过实现接口的类实例化的对象来调用,而类方法只 ...

  9. Java接口中的方法

    接口中可以含有变量和方法.但是,接口中的变量会被隐式地指定为public static final变量(并且只能是public static final变量,用private修饰会报编译错误),而方法 ...

随机推荐

  1. JQuery validate 在IE兼容模式下出现 js错误(成员找不到)的修正:

    JQuery validate 在IE兼容模式下 下出现 js错误(成员找不到)的修正: // Add novalidate tag if HTML5. //this.attr( "nova ...

  2. PageRank算法

    PageRank,网页排名,又称网页级别,传说中是PageRank算法拯救了谷歌,它是根据页面之间的超链接计算的技术,作为网页排名的要素之一.它通过网络浩瀚的超链接关系来确定一个页面的等级.Googl ...

  3. Grid_Oracle Grid Infrastructure概念介绍(概念)

    2014-03-09 Created By BaoXinjian Thanks and Regards

  4. 如何修改tomcat的端口

    <Connector port="8485" protocol="HTTP/1.1" connectionTimeout="20000" ...

  5. mysql 正则

    mysql 正则学习 基本字符匹配 select desk from dealer_info where desk regexp "82107777"; . 表示匹配任意一个字符 ...

  6. Mobirise

    网站建设器Mobirise v1.9.2 免费版 - 绿色软件联盟 2015年9月5日 - 网站建设器Mobirise是一个用户友好的程序,使您可以构建桌面和移动网站,准备在Javas cript中. ...

  7. 运用BigDecimal精确计算

    package com.wzh.test; import java.math.BigDecimal; public class test { /** * @param args */ public s ...

  8. centos安装——usb安装技术问题整理

    1) 官网How tohttp://wiki.centos.org/HowTos/InstallFromUSBkey 2)我安装碰到的问题:http://www.douban.com/group/to ...

  9. vb eof详解

    源地址:https://zhidao.baidu.com/question/87122186.html?qbl=relate_question_1&word=eof%20sql&ski ...

  10. Linux内核学习之路

    每当学习到一定阶段自己觉得还行时,就会搜一些别人的文章. 这篇文章是原作者14年3月写的.转过来与自己共勉.学习累了就换着学也挺好 原文: 现在回首看看,接触Linux已经很长时间了. 在大三的时候开 ...