如何用PHP 发送HTTP的GET方法后正常显示获取的网页数据?

tsingmei 2007-05-14 07:23:33
我用下面代码

$o_trans = new Transferer( 'www.itpub.net', 80 ); // start work
//$o_trans->Send( 'get', '', '', TRUE ); // receive base cookie
//$o_trans->AddParam( 'username', 'tsingmei' ); // set login user name
//$o_trans->AddParam( 'password', 'zhanghai' ); // set login user password
//$o_trans->AddParam( 'submit', 'LOGIN' ); // add login button
//$o_trans->Send( 'post', 'login.php', 'http://www.itpub.net/', TRUE ); // login and update cookie
//$o_trans->Send( 'GET', 'click.php', 'http://www.itpub.net/referer.php' ); // try click

//function Send ( $method = 'GET', $uri = '', $fromUrl = '', $updCookie = FALSE )

$mRequest='';
$mRequest = 'GET /forum3.html HTTP/1.1'. NL. 'Accept: */*' . NL;
$mRequest .= 'Referer: http://www.itpub.net/index.php'. NL;
$mRequest .= 'Accept-Language: zh-cn' . NL
. 'Accept-Encoding: gzip, deflate' . NL
. 'User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)'. NL
. 'Host: www.itpub.net'. NL
. 'Connection: Keep-Alive'. NL;

$mRequest .= 'Cookie: bblastvisit=1174440511; itpubtag=221.6.3.74.1174440530209385; sessionhash=4e413a6dd911dc0a5cc64ea2f981e202; sso_token=66e4c1718aca995909a6f52605df9296441474; itpub_token=66e4c1718aca995909a6f52605df9296441474; bbuserid=36327; bbpassword=d146bbe22becfca96ff6005207d5649f; bbusername=tsingmei; PHPSESSID=ce239e01d99b592de0af4f728abdb156'. NL;
$mRequest .= NL;

$h_sock = socket_create( AF_INET, SOCK_STREAM, SOL_TCP );
$m_result = socket_connect( $h_sock, "www.itpub.net", 80 );
// Send Request Data through TCP Socket.
$m_result = socket_write( $h_sock, $mRequest, strLen( $mRequest ) );
$m_result = socket_read( $h_sock, 1024, PHP_BINARY_READ );
//$a_data = explode( NL . NL, $m_result );
///$mResponse = $a_data[0];
$response = preg_split('/\r\n\r\n/', $m_result, -1, PREG_SPLIT_NO_EMPTY);
echo $response['header'] = $response[0];

echo $response['content'] = $response[1];
echo $response['status_code'] = substr($response['header'],
strpos($response['header'],' ') + 1, 3);
echo $response['error'] = $error;

socket_clear_error( $h_sock );
socket_close( $h_sock );

$o_trans->Close();

结果输出如下乱码,它们好像用了gzip压缩,如何得到正常信息?
--------------------------------------------------------------
HTTP/1.0 200 OK Date: Mon, 14 May 2007 11:23:21 GMT Server: Apache/2.0.53 (Unix) PHP/4.3.11 X-Powered-By: PHP/4.3.11 Set-Cookie: sessionhash=44134d9f94a5200e5c3cfb3b5dffb459; path=/; domain=.itpub.net Content-Length: 67697 Content-Encoding: gzip Vary: Accept-Encoding Content-Type: text/html; charset=gb2312 X-Cache: MISS from cache51.it168.com Connection: keep-alive?靰隬G讹鐇5歶cゎ?冩b?s癮痙瞵Y?〢鞨jE?揧鐋筥颹縻龑=搎lg 癜? 2聮鉏N&N&墖8??荵藩_j翟B?,cu鳟]华鳋债]籞5?kh╋鳰k#8辯?礊:谲TtU脹苲儭。Ax`襝8?拁栨h芆z 喥?请鹙<溝?O憂艨忊H噌窣鮊堫礠滱婖鑰嬹s敓1?降哊&?鯃蠈?/録 ?/5yq??MPㄩ?^?O_?訲/鸠觇 Preu? 礼€薈Y姭韗F淍盏w?p恀爏?辑g9瘥c-';淊Gc5繫伋G鉞輭︽逿?书]?@j?~@'獡粞揶j???斪 糫?H?uG杶棯隼YT桍B瀃~ai駉好@譇?湦z@d酖逢??'蒨愰?;哧╦h琽ihj9Y B~7粢~闔}KsK[5pzC敧n9ZW飋吹?貾%旋?巭弨銔Mo飥投羏mikhl玧n?7???馫GKk?蛵窃E闛档#?み-?m殍h9慐 ?u7€?縂?$x? 畠弾?鼏$眘S漝人┢(??掳BnG@{}[Ks笱:(F]{X噻?200
...全文
549 4 打赏 收藏 举报
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
cymple 2007-05-19
帮顶
  • 打赏
  • 举报
回复
Go_Rush 2007-05-15
去掉这行

. 'Accept-Encoding: gzip, deflate' . NL
  • 打赏
  • 举报
回复
iasky 2007-05-15
或者用curl函数库把
  • 打赏
  • 举报
回复
iasky 2007-05-15
看手册
  • 打赏
  • 举报
回复
相关推荐
发帖
基础编程

2.1w+

社区成员

从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
帖子事件
创建了帖子
2007-05-14 07:23
社区公告
暂无公告