fsockopen 关于web通信协议问题!

askkk 2003-10-16 05:10:45
<?php
$fp = fsockopen ("www.example.com", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br>\n";
} else {
fputs ($fp, "GET / HTTP/1.0\r\nHost: www.example.com\r\n\r\n");
while (!feof($fp)) {
echo fgets ($fp,128);
}
fclose ($fp);
}
?>
这只能取得首页的文件,哪位能告知如何向web服务器传递变量及相关信息。最好是具体的通信格式!
...全文
39 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
bonniewater 2003-10-16
  • 打赏
  • 举报
回复
mark
xuzuning 2003-10-16
  • 打赏
  • 举报
回复
simple post method
redact 发表于 2002-4-8 18:14 PHP编程 ←返回版面

// simple post method
// version 1.0 by Andrus (andrus@vnet.ee)

// Disclaimer:
// everyone can change or use this code however and wherever they want ;)

// NB! For posting to Microsoft platform webservers you may need to change newlines "\n" to "\r\n"
// Microsoft always breaks standards ...

// send out "browser" headers
function send_headers ($fp) {
fputs ($fp, "Accept: */*\n");
fputs ($fp, "Accept-Language: en\n");
fputs ($fp, "Connection: Keep-Alive\n");
fputs ($fp, "User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)\n");
}

// post data and return reply
function post_data ($host, $url, $data) {
$fp = @fsockopen ($host, 80, $errno, $errstr, 120);
$ret = "";
if (strncasecmp ($url, "http://", 7) == 0) $url = substr ($url, 7);
$p = strpos ($url, '/');
if (empty ($p)) {
$req = "/";
} else {
$req = substr ($url, $p);
}
if ($fp) {
fputs ($fp, "POST $req HTTP/1.0\n");
send_headers ($fp);
fputs ($fp, "Content-type: application/x-www-form-urlencoded\n");
$out = "";
while (list ($k, $v) = each ($data)) {
if(strlen($out) != 0) $out .= "&";
$out .= rawurlencode($k). "=" .rawurlencode($v);
}
$out = trim ($out);
fputs ($fp, "Content-length: ".strlen($out)."\n\n");
fputs ($fp, "$out");
fputs ($fp, "\n");
while(!feof($fp)){
$ret .= fgets($fp,128);
}
fclose ($fp);
}
return $ret;
}
// example how to use:

// following code will post variables "login" and "pass" to server "www.something.com" script "/submit.php"
$reply = post_data ("www.something.com", "/submit.php", array ("login" => $username, "pass" => $password));

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧