当我的客户端程序向www服务器发送了请求后,服务器会向客户端程序返回一些回应内容。
如向www.sohu.com发送请求后,会有如下一些内容。
HTTP/1.0 200 OK
Date: Wed, 12 Mar 2003 02:24:51 GMT
Server: Apache/1.3.26 (Unix) mod_gzip/1.3.19.1a
Vary: Accept-Encoding
Cache-Control: max-age=70
Expires: Wed, 12 Mar 2003 02:26:01 GMT
Last-Modified: Wed, 12 Mar 2003 02:24:51 GMT
ETag: W/"2cc75-19c15-3e6e9a7c"
Accept-Ranges: bytes
Content-Length: 105493
Content-Type: text/html
Age: 16
X-Cache: HIT from squid.sohu.com
Connection: close<html>
<!-- head -->
<head>
<title>搜狐首页</title>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<meta name="Create-time" content="2003-03-12 10:25:00">
<style type=text/css>
<!--
td,body,input,select {font-size: 12px;}
.white {font-size: 12px;color: #FFFFFF;text-decoration: none;}
.blue { text-decoration: underline;color:#000099;line-height: 18px;}
.blue1{ text-decoration: underline;color:#000099;line-height: 20px;}
a:hover {color: #cc0000;text-decoration: underline;}
a:active {color:#800080}
a.nav1 {font-size: 12px;color: #FFFFFF;text-decoration: none;}
a.nav1:hover {color: #FFEFA5;text-decoration: underline;}
a.nav1:active {color:#800080}
.finput {BORDER-RIGHT: 0px ridge;BORDER-TOP: 1px ridge #727272; BORDER-LEFT: 1px ridge #727272; BORDER-BOTTOM: 0px ridge;font-size: 12px;}
.foxinput {BORDER-RIGHT: 1px ridge; BORDER-TOP: #ffffff 1px ridge; BORDER-LEFT: #ffffff 1px ridge; BORDER-BOTTOM: 1px ridge; BACKGROUND-COLOR: #cccccc}
.black {color: #000000; text-decoration: none;line-height: 18px;}
.blue2 {line-height: 18px;color: #0033FF;text-decoration: underline;}
.blue3 {line-height: 18px;color: #0031FF;text-decoration: none;}
.blue4 {font-size: 12px;color: #0031FF;text-decoration: underline;}
.blue5 {text-decoration: underline;color:#000099;line-height: 19px;}
.blue6 {text-decoration: none;color:#000099;line-height: 19px;}
.blue7 {color: #0031FF;text-decoration: none;}
.blue8 {line-height: 18px;color: #000099;text-decoration: none;}
.nc {font-size: 12px;line-height: 18px;letter-spacing: 2px;}
//-->
</style>
</head><!-- end head -->
<!-- body -->
<body bgcolor=#FFFFFF vlink=#000099 leftmargin=0 topmargin=4>
<script src="./startlog.js"></script><!-- end body -->
<center>
<table width=760 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=632>
<!-- freemail -->
<table border=0 cellpadding=0 cellspacing=0>
但是令人奇怪的是,向www.sina.com.cn发送后,却回应了一堆乱码。如下:
HTTP/1.0 200 OK
Date: Wed, 12 Mar 2003 02:04:57 GMT
Server: Apache/2.0.43 (Unix)
Cache-Control: max-age=60
Expires: Wed, 12 Mar 2003 02:05:57 GMT
Last-Modified: Wed, 12 Mar 2003 01:58:11 GMT
Accept-Ranges: bytes
Content-Encoding: gzip
Vary: Accept-Encoding
Content-Length: 37193
Content-Type: text/html
X-Cache: HIT from gro37-1.sina.com.cn
X-Cache-Lookup: HIT from gro37-1.sina.com.cn:80
Connection: close?      斫鵺SG??^?囉顄1糮k?XY?鼿?t黜椬薑杁[ K?cLnk淣$捏<铣鍣&s萷閷刵 っz焆u??[矟慆緆Kgㄚ祂诪j邹?洘鲈驡斶?蕶隍p(^ (緞獯踋|嘢)9?>鑠('c裫艁逌肬夑镑7??鑧u0酳?墯说ス$???羂E齎殯^J罔錍娍??錘椕檵V蠳"?缴憽贆嶅置6?7鈮鷓P≈JYo$j凜B憵谀亁0?擶*衱~<t9x嗅t枵咪?擶p4v饂靽疄v笖W隆H0?Jt胳羙x?q篞膐溎u竭"帝搸B鉫G=N鄶Gc乣,??? + 咗鉆壇逖D"Zf89?媷蕔?暠hm$恛妗嬃X"澉咉}酨e?!/?D嵺? 紀%
TK-* h$k?H?恅.v %駂8牜?q晉J?@噤?瀻昞?葞煝
"?/嗏?謱牣B忀U澉|﨑鑒P籙QA/騕UQL屨?熭■奇*鬐c綝(9塅倗坛K ?40瞴I婪?A雒€f﹢o鰥奞6g*?8钚??銄?n
囲跬痂?徳?'h膝兂?鍡寷絚榺諵Fx4骆蝡4*a?w妫1緮齢??崌嶆 ?s0u吗鋊?ら?#/?!?R喾荒歎鏢?*ォA趴D?D痹i!苽a嬃C楏C栳褹?b愽C寘?阈_驎牵嶷D跅闎丏誂圦FN俘-腧P8敤?X
?Z坖蹜`濖蕂r斢'N?ㄘ!Z?/?u钤 ?T4晄/渁w摚??q隀g?:-垩犞?裨賁GO?u钕*錙焮??4舲b屔獒紝f?g膝?}﹂[璼!螆8(境佗=y波念P櫉鱼4佲??螜8(欜Ga焉?(.(畬A眐通爌堵A蓯a笌9鎟j牳M牑?)kQo姘峣 P?R觞盤MB ?暤臼`閥逧縁?4V遒P ?/鷅
翢?J???揝Q佖岶?v齾歚$?廁X葵擉娐袡?狿鳊中?龡?幤??灕暎?;缃D褲桁@n?v1X廩?r裩杠; B5鯐噧0╤槷?倄?q€眮R份~€硜Rg?w!接W冡xPj '瑐姩?鞠舳?5,叄昬褛蜿Pb邁吹噽z&}>骇T 圊j U€嘊憘犏Hmu罞_?x負?c?謿:銒请漳氪裗╞隭)-U鸰賰K?{ス??{$▓;D#スd}促獇A<??蚠?El| 鴸K困4#p纎苽壼XDI镍P鱻u钯C?茐椪?G齃5K刍跅赲?-?ńWA录M闳潤徏如ni&,V黫O瘵皘N裸臥崋?7湖廋沆mI儢t柩p鉚|禩赏U鲱e雌宽W變??翂e?t璘綻?KN暊锃蔲伩?3奔j X C妶?A?21拹蚾僛臋o麂;妉嚙ㄘQ'o唺b研烞4を&枣洧涚帨:}賑[?启SYMTp4?1\?~e鬤晱3{嵶这是为什么?是sina对回应内容加密了还是多字节的问题?

解决方案 »

  1.   

    看看是不是UTF-8编码
    我以前自己写过这个东东看过新浪的首页,没有看到乱码跟进
      

  2.   

    我用UltraEdit打开读取的内容。然后选择字码转换功能,可还是看到一堆乱码。
    下面是sina的首页的源文件的一部分。
    <!--SINA Jit Published at 2003-3-11 21:57:39 From 103-->
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=gb2312"><title>新浪首页</title>
    <style type=text/css>
    td,p,li,input,select {font-size:12px;}
    .C01 {color:#ffffff}
    .L13 {line-height:130%}
    .L15 {line-height:150%}
    .L17 {line-height:170%}
    .F7 {font-size:7px;}
    .F16 {font-size:16px;}
    .s01 {border-top:1;border-left:1;border-right:1;border-bottom:1;border-style:inset;background-color:#ffffff;vertical-align:text-bottom}
    .s02 {border-left:1 ridge #ffffff;border-top:1 ridge #ffffff;border-bottom:1;border-right:1;border-style:ridge;background-color:#cccccc}
    .s03 {border-top:1;border-left:1;border-right:1;border-bottom:1;border-style:solid;border-color:#939598;background-color:#ffffff;vertical-align:text-bottom}
    A:link {color:#00007f;}
    A:visited {color:#65038e;}
    A:active {color:#ff0000;}
    A:hover {color:#ff0000;}
    A.a01:link {text-decoration:none;color:#ffffff;}
    A.a01:visited {text-decoration:none;color:#ffffff;}
    A.a01:active {text-decoration:none;color:#eeeeee;}
    A.a01:hover {text-decoration:none;color:#ffffff;}
    A.a02:link {color:#0000ff;}
    A.a02:visited {color:#0000ff;}
    A.a02:active {color:#ff0000;}
    A.a02:hover {color:#ff0000;}
    A.a03:link {text-decoration:none;color:#000000;}
    A.a03:visited {text-decoration:none;color:#000000;}
    A.a03:active {text-decoration:none;color:#ff0000;}
    A.a03:hover {text-decoration:none;color:#ff0000;}
    A.a04:link {text-decoration:none;color:#00007f;}
    A.a04:visited {text-decoration:none;color:#00007f;}
    A.a04:active {text-decoration:none;color:#ff0000;}
    A.a04:hover {text-decoration:none;color:#ff0000;}
    A.a05:link,A.a05:visited {text-decoration:none;color:#0000ff;}
    A.a05:active,A.a05:hover {text-decoration:underline;color:#0000ff;}
    .c03{color:#000000;border-color:#000000;}
    #mydown{position:relative;z-index:0;top:0;left:0;}
    #mydown1{position:absolute;z-index:0;top:0;left:0;width:100;height:240;visibility:hidden;}
    #mydownnew {
     LEFT: 0px; POSITION: relative; TOP: 0px
    }
    #mydown2 {
     HEIGHT: 240px; LEFT: 0px; POSITION: absolute; TOP: 0px; VISIBILITY: hidden; WIDTH: 100px
    }A.a251:link,A.a251:visited {text-decoration:none;color:#ffffff;}
    A.a251:active,A.a251:hover {text-decoration:underline;color:#ffffff;}A.a252:link,A.a252:visited {text-decoration:none;color:#FF7901;}
    A.a252:active,A.a252:hover {text-decoration:underline;color:#FF7901;}A.a253:link,A.a253:visited {text-decoration:none;color:#0167FF;}
    A.a253:active,A.a253:hover {text-decoration:underline;color:#0167FF;}A.a254:link,A.a254:visited {text-decoration:none;color:#3CAC32;}
    A.a254:active,A.a254:hover {text-decoration:underline;color:#3CAC32;}
    </style>
     
    <script language=javascript>
    <!-- Hide 
    var newWindow = null
    function windowOpener(loadpos)
    {       
            if (! newWindow || newWindow.closed)
            {
            newWindow = window.open(loadpos,"surveywin","toolbar,resizable,scrollbars,dependent,width=400,height=280");
            }else
            {
                    newWindow.focus();
            }
    }function log_submit(){
    var ProNo = document.login.mynum.value;
    var User = document.login.u.value;
    var Passwd = document.login.psw.value; if(ProNo == 1){
    if(Passwd!=""){
    document.login.action="http://mail.sina.com.cn/cgi-bin/login.cgi";
    document.login.submit();
    return true;
    }
    else {
    window.location="http://mail.sina.com.cn";
    return false;
    }

      

  3.   

    老兄,注意Content-Encoding: gzip
    返回的是gzip格式压缩了的主页
      

  4.   

    如果你不想服务器返回Encoding了的数据的话,可以加上这个头
    Accept-Encoding: identity;q=1.0,*;q=0解释:
    identity表示不做Encoding的编码方式
    q是encoding的权值,1.0为最大,0则表示disable这个编码方式
    *代表未列出的其他编码方式