喜悦国际村 
» 游客:  注册 | 登录 | 搜索 | 统计 | 帮助

RSS 订阅当前论坛  

喜悦证交所已经关闭

上一主题 下一主题
     
标题: [问题] 求助:Socket获取的数据如何处理?  
 
sih (sih)
注册会员
Rank: 2
初级会员



UID 62637
精华 0
积分 151
帖子 97
金钱 151 喜悦币
威望 0
人脉 0
阅读权限 20
注册 2004-12-21
状态 离线
[广告]: q m
求助:Socket获取的数据如何处理?

函数:

<?php
function get($url

$url eregi_replace('^http://'''$url); 
$temp explode('/'$url); 
$host array_shift($temp); 
$path '/'.implode('/'$temp); 
$temp explode(':'$host); 
$host $temp[0]; 
$port = isset($temp[1]) ? $temp[1] : 80

$fp = @fsockopen($host$port$errno$errstr30);
if (
$fp

@
fputs($fp"GET $path HTTP/1.1rn"); 
@
fputs($fp"Host: $hostrn"); 
@
fputs($fp"Accept: */*rn"); 
@
fputs($fp"Referer: [url]http://$host/[/url]rn"); 
@
fputs($fp"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)rn"); 
@
fputs($fp"Connection: Closernrn"); 


$Content ''
while (
$str = @fread($fp4096)) 
$Content .= $str
@
fclose($fp); 

return 
$Content
}
?>
然后获取回来HTTP头、正文,还多出来一些不明数据?

HTTP/1.1 200 OK
Date: Thu, 03 Apr 2008 06:05:19 GMT
Server: Apache
Content-Disposition: attachment; filename="5342.py"
Connection: close
Transfer-Encoding: chunked
Content-Type: text/plain


129(或2cf等,可变)
正文正文正文……
0

该如何把正文分离出来呢?

[ 本帖最后由 sih 于 2008-4-3 02:35 PM 编辑 ]
2008-4-3 02:19 PM#1
查看资料  发短消息  顶部
 
sih (sih)
注册会员
Rank: 2
初级会员



UID 62637
精华 0
积分 151
帖子 97
金钱 151 喜悦币
威望 0
人脉 0
阅读权限 20
注册 2004-12-21
状态 离线
[推荐阅读] 请教java编译工具ant的使用
求助:谁知道那些该死的不明字符该怎么处理?怎样做才能够不出现这些字符?

[ 本帖最后由 sih 于 2008-4-3 10:09 PM 编辑 ]
2008-4-3 10:06 PM#2
查看资料  发短消息  顶部
     


  可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题 | 开通个人空间  


 




Powered by Discuz! 6.1.0  © 2001-2010 Comsenz Inc.
Processed in 0.096874 second(s), 6 queries

(冀ICP备05009913号) 管理员:sadly 邮箱/MSN: sadly@phpx.com QQ:824008(长隐) 清除 Cookies - - Archiver - WAP