<?php
function HTTP_Post($URL,$data, $referrer="") { // parsing the given URL
$URL_Info=parse_url($URL); // Building referrer
if($referrer=="") // if not given use this script as referrer
$referrer=$_SERVER["SCRIPT_URI"]; // making string from $data
foreach($data as $key=>$value)
$values[]="$key=".urlencode($value);
$data_string=implode("&",$values); // Find out which port is needed - if not given use standard (=80)
if(!isset($URL_Info["port"]))
$URL_Info["port"]=80; // building POST-request:
$request.="POST ".$URL_Info["path"]." HTTP/1.1\n";
$request.="Host: ".$URL_Info["host"]."\n";
$request.="Referer: $referer\n";
$request.="Content-type: application/x-www-form-urlencoded\n";
$request.="Content-length: ".strlen($data_string)."\n";
$request.="Connection: close\n";
$request.="\n";
$request.=$data_string."\n"; $fp = fsockopen($URL_Info["host"],$URL_Info["port"]);
fputs($fp, $request);
while(!feof($fp)) {
$result .= fgets($fp, 128);
}
fclose($fp); return $result;
} $output1=HTTP_Post("http://www.example.com/script1.php",$_POST);
$output2=HTTP_Post("http://www.example.net/script2.php",$_POST);
?>

注意:

Host:对应的值不能带有http://

Php 使用 fsockopen发送http请求的更多相关文章

  1. php 使用fsockopen 发送http请求

    需求背景 在公司开发这么一个需求,每天三次定时催付待客服催付状态的订单,设定每天15.16.17点三次执行job任务来给一批订单打电话催付,需要三个时间点都把待客服催付的订单拨打一遍电话,根据数据组统 ...

  2. php中使用fsockopen实现异步请求

    php执行一段程序,有可能几毫秒就执行完毕,也有可能耗时较长.例如,用户下单这个事件,如果调用了些第三方服务进行发邮件.短信.推送等通知,可能导致前端一直在等待.而有的时候,我们并不关心这些耗时脚本的 ...

  3. 【荐】怎么用PHP发送HTTP请求(POST请求、GET请求)?

    file_get_contents版本: <?php /** * 发送post请求 * @param string $url 请求地址 * @param array $post_data pos ...

  4. php发送http请求方法实例及详解

    http请求有get,post. php发送http请求有三种方式[我所知道的有三种,有其他的告诉我]. file_get_contents();详情见:http://www.whosmall.com ...

  5. PHP模拟发送POST请求之四、加强file_get_contents()发送POST请求

    使用了笨重fsockopen()方法后,我们开始在PHP函数库里寻找更简单的方式来进行POST请求,这时,我们发现了PHP的文件函数也具有与远程URL交互的功能. 最简单的是fopen()和fread ...

  6. HTTP 笔记与总结(3 )socket 编程:发送 GET 请求

    使用 PHP + socket 模拟发送 HTTP GET 请求,过程是: ① 打开连接 ② 构造 GET 请求的数据:写入请求行.请求头信息.请求主体信息(GET 请求没有主体信息) ③ 发送 GE ...

  7. 怎么用PHP发送HTTP请求(转载)

    本文转自:http://blog.snsgou.com/blog/161.html  file_get_contents版本: /** * 发送post请求 * @param string $url ...

  8. socket编程发送GET请求

    可以根据几根url地址,分析出主机,地址,协议等,然后用封装成的类拼接成GET请求信息,用fsockopen连接主机,进行读取操作,获取响应信息,打印 <?php //http连接接口 inte ...

  9. php发送http请求

    http请求有get,post. php发送http请求有三种方式[我所知道的有三种,有其他的告诉我]. file_get_contents();详情见:http://www.cnblogs.com/ ...

随机推荐

  1. .Net Mvc4 Kendo Grid Demo

    看见人家项目中用到了Kendo Grid组件,感觉不错,于是就没有压制住自己内心的好奇心!嘿嘿,咱们开始吧,步骤很简单,理解起来也很容易. 首先我们创建一个空的ASP.NET MVC 4 Web 应用 ...

  2. jquery不限图片焦点图

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. css样式写一个三角形

    <style> .test{ border-color:transparent #abcdef transparent transparent; border-style:solid; b ...

  4. java如何引入接口中定义的常量

    接口 (A.java) : package config; public interface A { String PROJECT_ROOT_DIR = System.getProperty(&quo ...

  5. 转载:Ajax及 GET、POST 区别

    转载:Ajax及 GET.POST 区别 收获: xhr.setRequestHeader(), xhr.getResponseHeader() 可以设置和获取请求头/响应头信息; new FormD ...

  6. css多行文本垂直居中问题研究

    css多行文本垂直居中问题研究 <body> <h2>垂直居中对齐</h2> <style> *{margin:0; padding:0;} div { ...

  7. 一步一步学习SignalR进行实时通信_2_Persistent Connections

    原文:一步一步学习SignalR进行实时通信_2_Persistent Connections 一步一步学习SignalR进行实时通信\_2_Persistent Connections Signal ...

  8. http 响应头之location

    <pre name="code" class="html">jrhmpt01:/root# cat login_yylc.pl use LWP::U ...

  9. [LeetCode] Best Time to Buy and Sell Stock Solution

    Say you have an array for which the ith element is the price of a given stock on day i. If you were ...

  10. ceph基本操作整理

    一.ceph基本操作: 启动osd.mon进程: start ceph-osd id=X start ceph-mon id=YYY 关闭osd.mon进程: stop  ceph-osd id=X ...