response问题 socket 应该没有明确上限,反而PHP单个线程使用内存数量要考虑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 楼上的看看,代码如下post1.php:class post2Url{ function __construct( $url, $host, $port="" ) { $this->url = $url; $this->host = $host; $this->port = ($port == "")? 80 : $port; } //$data是一数组 //数组$key是提交时的变量名 //数组$val是提交时的变量值 //例如array("a"=>"b") POST时为a=b function post( $data ) { $postdata = ""; while ( list( $key, $val ) = each( $data ) ) { $postdata .= $key . "=" . $val . "&"; } $postdata = substr( $postdata, 0, -1); return $this->postval( $postdata ); } function postval( $postdata ) { $error; $errorno; $datalen = strlen( $postdata ); $fp = fsockopen( $this->host, $this->port,$errorno,$error,30); if( $fp ){ $act = "POST ".$this->url." HTTP/1.1\r\n"; $act .= "Accept: text/html, image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*\r\n"; // $act .= "Referer: http://localhost/post2.php\r\n"; // $act .= "Accept-Language: zh-cn\n"; $act .= "Content-Type: application/x-www-form-urlencoded\r\n"; // $act .= "Accept-Encoding: gzip, deflate\n"; $act .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n"; $act .= "Host: ".$host."\r\n"; $act .= "Connection: Close\r\n"; $act .= "Content-Length: ".$datalen."\r\n"; $act .= "Connection: Keep-Alive\r\n"; // $act .= "Cache-Control: no-cache\n"; // $act .= "Cookie: new_loginname=%c6%da%b4%fd2004; new_loginid=5372515; new_loginpwd=9F4F996CB25703DF; usersms_pop_type=1\n"; $act .= "\r\n"; $act .= $postdata; // echo $act; fputs( $fp, $act); $i=1; while( !feof($fp)) { $msg = fgets($fp,4096); if($i==10)//把response头去掉,只显示内容 { header('Content-Type: text/xml'); echo $msg; } $i++; } fclose( $fp ); //echo $msg; } else{ echo $errorno; echo "<br />".$error; return false; } }}$url="/post2.php";$host="127.0.0.1";$post2url=new post2url($url,$host,'80');$data=array();$str="<?xml version=\"1.0\" encoding=\"UTF-8\"?>";$str.="<response>";$str.="<code>200 </code>";$str.="<desc>Ok </desc>";$str.="</response>";$data['name']=$str;$post2url->post($data);post2.phpheader('Content-Type: text/xml');echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";echo "<books>";//这里是数据内容,可以有很多echo "</books>"; $msg = fgets($fp,4096); if($i==10)//把response头去掉,只显示内容{ header('Content-Type: text/xml'); echo $msg;//这句只会运行一次,最多输出4096字节=.=} 再问下yctin,那个post1.php是我网上找的,请问能解释一下$fp的处理过程吗?他是不是有大小限制的 改了一下,发觉大小好像是没有限制的,但是发送的时候会把整块内容分割成一个一个包发送,接受的时候就不是完整的xml文件了,中间被插入了一些包之间的分割符(以html文本输出内容是发现的)。不知道我的理解对不对?能不能找出这些节点,可以让我重新组成完整的xml文件输出呢? 如果你只是想取得一个档案的内容...echo file_get_contents("http://127.0.0.1/post2.php"); 我的post2.php要针对post1.php传递的变量,作相对处理后,返回给post1.php,一个xml结构的结果。顺便问一下,怎么在html网页里完整的显示xml内容,不用header(。type/xml)的话。 curl模拟登陆163邮箱如何确定COOKIEFILE的值 请教个关于jpgraph的问题 简单配置问题 乱码问题求教 linux crontab 执行php PHP连接PostgreSQL代码? 修改密码的问题 php发送问题 javascript怎么读取服务器时间 编码转换问题!急急急急急!请教 请大家帮忙看看啊!!! goole 搜索提示 用什么事件触发的
post1.php:class post2Url
{
function __construct( $url, $host, $port="" )
{
$this->url = $url;
$this->host = $host;
$this->port = ($port == "")? 80 : $port;
}
//$data是一数组
//数组$key是提交时的变量名
//数组$val是提交时的变量值
//例如array("a"=>"b") POST时为a=b
function post( $data )
{
$postdata = "";
while ( list( $key, $val ) = each( $data ) ) {
$postdata .= $key . "=" . $val . "&";
}
$postdata = substr( $postdata, 0, -1);
return $this->postval( $postdata );
}
function postval( $postdata )
{
$error;
$errorno;
$datalen = strlen( $postdata );
$fp = fsockopen( $this->host, $this->port,$errorno,$error,30);
if( $fp ){
$act = "POST ".$this->url." HTTP/1.1\r\n";
$act .= "Accept: text/html, image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*\r\n";
// $act .= "Referer: http://localhost/post2.php\r\n";
// $act .= "Accept-Language: zh-cn\n";
$act .= "Content-Type: application/x-www-form-urlencoded\r\n";
// $act .= "Accept-Encoding: gzip, deflate\n";
$act .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n";
$act .= "Host: ".$host."\r\n";
$act .= "Connection: Close\r\n";
$act .= "Content-Length: ".$datalen."\r\n";
$act .= "Connection: Keep-Alive\r\n";
// $act .= "Cache-Control: no-cache\n";
// $act .= "Cookie: new_loginname=%c6%da%b4%fd2004; new_loginid=5372515; new_loginpwd=9F4F996CB25703DF; usersms_pop_type=1\n";
$act .= "\r\n";
$act .= $postdata;
// echo $act;
fputs( $fp, $act);
$i=1;
while( !feof($fp))
{
$msg = fgets($fp,4096);
if($i==10)//把response头去掉,只显示内容
{
header('Content-Type: text/xml');
echo $msg;
}
$i++;
}
fclose( $fp );
//echo $msg;
}
else{
echo $errorno;
echo "<br />".$error;
return false;
}
}
}$url="/post2.php";
$host="127.0.0.1";
$post2url=new post2url($url,$host,'80');
$data=array();
$str="<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
$str.="<response>";
$str.="<code>200 </code>";
$str.="<desc>Ok </desc>";
$str.="</response>";
$data['name']=$str;
$post2url->post($data);post2.phpheader('Content-Type: text/xml');
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
echo "<books>";
//这里是数据内容,可以有很多
echo "</books>";
$msg = fgets($fp,4096);
if($i==10)//把response头去掉,只显示内容
{
header('Content-Type: text/xml');
echo $msg;//这句只会运行一次,最多输出4096字节=.=
}
不知道我的理解对不对?能不能找出这些节点,可以让我重新组成完整的xml文件输出呢?
echo file_get_contents("http://127.0.0.1/post2.php");
顺便问一下,怎么在html网页里完整的显示xml内容,不用header(。type/xml)的话。