【发布时间】:2011-01-22 23:20:44
【问题描述】:
我正在尝试使用 fsockopen 发布数据,然后返回结果。 这是我当前的代码:
<?php
$data="stuff=hoorah\r\n";
$data=urlencode($data);
$fp = fsockopen("www.website.com", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "POST /script.php HTTP/1.0\r\n";
$out .= "Host: www.webste.com\r\n";
$out .= 'Content-Type: application/x-www-form-urlencoded\r\n';
$out .= 'Content-Length: ' . strlen($data) . '\r\n\r\n';
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
?>
它应该是回显页面,它正在回显页面,但是这里是script.php的脚本
<?php
echo "<br><br>";
$raw_data = $GLOBALS['HTTP_RAW_POST_DATA'];
parse_str( $raw_data, $_POST );
//test 1
var_dump($raw_data);
echo "<br><br>":
//test 2
print_r( $_POST );
?>
结果是:
HTTP/1.1 200 OK 日期:2010 年 3 月 2 日,星期二 格林威治标准时间 22:40:46 服务器:Apache/2.2.3 (CentOS) X-Powered-By: PHP/5.2.6 内容长度:31 连接:关闭 内容类型:文本/html;字符集=UTF-8 string(0) "" 数组 ( )
我有什么问题?为什么变量不发布其数据?
【问题讨论】:
-
我不能使用 curl 因为这将是开源的
-
“Curl 是免费且开放的软件” Curl 在 MIT/X 许可下获得许可。
-
你不能指望每个人(甚至是共享主机的人)都想要并获得 curl
-
我可能错了,但每个标题字段之后不应该只有一个 \r\n 吗?当然最后一个除外……
-
您是否启用了
always_populate_raw_post_data? php.net/manual/en/…