Discuz教程网

POST

[复制链接]
authicon 09927306 发表于 2011-1-12 17:02:43 | 显示全部楼层 |阅读模式

  1. function sendPost($postUrl, $data){
  2.     $URL = $postUrl;
  3.     $post_data = $data;
  4.     $referrer="";
  5.     // parsing the given URL
  6.     $URL_Info=parse_url($URL);
  7.     // Building referrer
  8.     if($referrer=="") // if not given use this script as referrer
  9.     $referrer=$_SERVER["SCRIPT_URI"];
  10.     // making string from $data
  11.     foreach($post_data as $key=>$value)
  12.     $values[]="$key=".urlencode($value);
  13.     $data_string=implode("&",$values);
  14.     // Find out which port is needed - if not given use standard (=80)
  15.     if(!isset($URL_Info["port"]))
  16.     $URL_Info["port"]=80;
  17.     // building POST-request:
  18.     $request.="POST ".$URL_Info["path"]." HTTP/1.1\\n";
  19.     $request.="Host: ".$URL_Info["host"]."\\n";
  20.     $request.="Referer: $referrer\\n";
  21.     $request.="Content-type: application/x-www-form-urlencoded\\n";
  22.     $request.="Content-length: ".strlen($data_string)."\\n";
  23.     $request.="Connection: close\\n";
  24.     $request.="\\n";
  25.     $request.=$data_string."\\n";
  26.     $fp = fsockopen($URL_Info["host"],$URL_Info["port"]);
  27.     fputs($fp, $request);
  28.     while(!feof($fp)) {
  29.        $result .= fgets($fp, 128);
  30.     }
  31.     fclose($fp);
  32.     $result = preg_replace(\'(.*)/Content-Type: text/html(.*)/is\',\'\\\\2\',$result);
  33.     return $result;
  34. }
复制代码






上一篇:php用SMTP发送邮件
下一篇:MYSQL分表优化
authicon lanyuqing 发表于 2011-6-17 20:59:50 | 显示全部楼层
强人,佩服死了。
authicon 夕梨二世 发表于 2011-6-20 01:00:03 | 显示全部楼层
看帖必回
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-3 04:03

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表