//用post向服务器发送信息
function posttohost($url, $data) {
$url = parse_url($url);
print_r($url);
if (!$url) return "couldn't parse url";
if (!isset($url['port'])) { $url['port'] = ""; }
if (!isset($url['query'])) { $url['query'] = ""; }
if(!is_array($data)) $data = array();
$encoded = "";
while (list($k,$v) = each($data)) {
$encoded .= ($encoded ? "&" : "");
$encoded .= rawurlencode($k)."=".rawurlencode($v);
} $fp = fsockopen($url['host'], $url['port'] ? $url['port'] : 80);
if (!$fp) return "Failed to open socket to $url[host]"; fputs($fp, sprintf("POST %s%s%s HTTP/1.0\n", $url['path'], $url['query'] ? "?" : "", $url['query']));
fputs($fp, "Host: $url[host]\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\n");
fputs($fp, "Content-length: " . strlen($encoded) . "\n");
fputs($fp, "Connection: close\n\n"); fputs($fp, "$encoded\n"); $line = fgets($fp,1024);
if (!eregi("^HTTP/1\.. 200", $line)) return; $results = ""; $inheader = 1;
while(!feof($fp)) {
$line = fgets($fp,1024);
if ($inheader && ($line == "\n" || $line == "\r\n")) {
$inheader = 0;
}elseif (!$inheader) {
$results .= $line;
}
}
fclose($fp); return $results;
}
//调用例
echo posttohost("http://.....",$_POST);
function posttohost($url, $data) {
$url = parse_url($url);
print_r($url);
if (!$url) return "couldn't parse url";
if (!isset($url['port'])) { $url['port'] = ""; }
if (!isset($url['query'])) { $url['query'] = ""; }
if(!is_array($data)) $data = array();
$encoded = "";
while (list($k,$v) = each($data)) {
$encoded .= ($encoded ? "&" : "");
$encoded .= rawurlencode($k)."=".rawurlencode($v);
} $fp = fsockopen($url['host'], $url['port'] ? $url['port'] : 80);
if (!$fp) return "Failed to open socket to $url[host]"; fputs($fp, sprintf("POST %s%s%s HTTP/1.0\n", $url['path'], $url['query'] ? "?" : "", $url['query']));
fputs($fp, "Host: $url[host]\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\n");
fputs($fp, "Content-length: " . strlen($encoded) . "\n");
fputs($fp, "Connection: close\n\n"); fputs($fp, "$encoded\n"); $line = fgets($fp,1024);
if (!eregi("^HTTP/1\.. 200", $line)) return; $results = ""; $inheader = 1;
while(!feof($fp)) {
$line = fgets($fp,1024);
if ($inheader && ($line == "\n" || $line == "\r\n")) {
$inheader = 0;
}elseif (!$inheader) {
$results .= $line;
}
}
fclose($fp); return $results;
}
//调用例
echo posttohost("http://.....",$_POST);
解决方案 »
- zend如何使用?
- 请教怎样用php在浏览器中图形显示数据库中数据
- 求助php-5.3.2-Win32-VC9-x86安装失败
- access的备注字段到底能容纳多少字符串?
- 我是菜鸟实在搞不懂,这是什么原因?
- 下面的php程序﹐為什么連接上數據庫卻取不到相應字段?請指教~~
- 讨论:php能否实现这样的功能,根据MAC 地址获取到ip并发送到固定的邮箱里头。
- 数据库操作函数前面加@与不加@的区别?
- PHP的mysql插入请求返回无报错,但数据库未更新
- 求教,关于PHP 5.6 PDO如何处理sql server 数据库
- 怎么取服务器时间和对方ip地址?
- PHP如何调用MDaemon的api接口?
请问一下 $_POST 的数据格式是什么?
是不是name1=value1&name2=value2
你不是要接受表单然后转发吗?
表单提交的数据就在$_POST里