socket获取到乱码的如何解决?

KerryLi 发布于 2017/06/14 09:54
阅读 221
收藏 0

代码如下:

     
             BufferedReader reader = new BufferedReader(
                     new InputStreamReader(socket.getInputStream(),"UTF-8"));
             //试过通过 gbk,gb2312,ios-....等接收, reader出来的都是 那种乱麻一样
             String line=null;
             StringBuilder buffer = new StringBuilder();
             while((line = reader.readLine())!=null){
                     buffer.append(line);
                   }
             String tmp = new String(buffer.toString());
//             System.out.println(new String(b)); 
             System.out.println("post recive : "+tmp);
             

 

获取的结果是:Expect: 100-continueeVMhZnoTqjAXUWsW?c?<?"?Qsi0?C??~???b,??Y?>?!??S?????????u?Q?9?4?Ie????F<;'?!Jg???N?C^k???.????{I?e?"?M?;??u?P?[\???Y?^???gN !???????3?@???9???df3?H6?????wtz????m7Ci44?3*E?5%?f??#?k?-???,??D?et?|N??$)?| Wu?C??Z]3 ???;?-/S?"u????3?q4??xg???'{??O??????UC?w? ?c?5j?0?T???N?YOKJ?V?????SY?Tz2om??4?b*???$>??DW?? ? ??lI??D(T?vi???S?4OK??r?\??\? p?J#?????????b??>????G!;i4?'??]L?=?.s??|絛J?*??.ou?????I?Q&2"?l?v?+??y???a??4:?N?C??}?????    ??WT.?S?&k5? ?    F?5z.kC??U? 7?{?68K????e+a?6?WW?ao??2??V?p?%C?:?AG.}?]?w>?T]???G?,(a??;????8??_??`??????????>???;bK??c5&?sO???? _8 xE?j l?=U?????G,k?'??????????B{{(??<??onOM r+??$,hA?/??<??viG?!5 hh??A ?V???    ???s?_ ?_*@??????/???#    ?G??'5!???*?.J?UD?l???7?????!?$}??Y?f{@@?????E+?{YL?m?P ?&??'?>???? ?wzV?N??~???V???#?^?nN?????Cq[???"?7H???GM{? ????NY2??3?~??'?v?A?>?sl??Q?~A?+?1?"??7?????#??>x???p?5X?5 ?;?,??&??'?????h????2?`G?#??B? '?+??5?*?0:W Q??4?????QV??(6?]?x?"H??_\e?I`r????S觤sH>???=7???t?V5?l??/nP??-??\?????8<t_d??><??R?yI?/?S?[?s g`????U,*j??? ??r?pi?%;????P?miN(&oH?F&z???j??&?k8L?????:??Nc????K4? ??????i*??C?????@ ?????k?4U?;???1?V??U????J???Om?{?M]4???;??q?~?9a???v???}l??T~~?|?????;)8??k??J?X?????~l?????VO;^??e?-5u?4?H-??M?X(?lBC??]<??gf?Z1??????X??;?B3??{c??I?????R?z?=? 6`?t??u?? ?E??C{??.22???k?'????n???oXu?CZ?????_?z???????1???-?H?V?$??7????_?J`??{????EVB;|??????;0(=2???`7?W??t#??Phe_?=Yh?a?k$?4???M??f?md???6i?;????X??S?j?$x???lqM???Y??" h?A?!l??]?X???7H?C!?T-N?ev???i???b??l?&&?t3"??q?\??|???2r?2??j????to??*?mt&}??s?i???R_?J?#"??-??;??qR V^?_??{G?Y??]?hrb???@Yk????3_???c?7q7?8??*k?O???n?9???R?C?d??%?"?{ ??3?o??????1??Wx!????(??rW???:??`,?{??D?m]+c???r????.&?*?!? ?'Nm????5E#)K}??1????}VG?????C+n?L?nX??S???;?n?14?????vlI#??"?g}??l????|?    ??5?iSA????n?:"I?]#?nMiZw?V?;???~c??&?t??W??X??X;    v;y???5x'lg??,S}X?bZ*g ???h-???/?Y?"8@'C?9?禿??????5[ELZ???p\P??44K?c ??N?WZ??? B?dI??eD=??O??(Q?4D|?~?:???O??QP?Yy?????(nae??x`?????+7?/????h??Q?}???K????????;???Dd?$?)?-??r?+y?8?9?ixE?R?!Y?%v^????4?"??)-:*&&g????H?V??w?@?? ;?SbP????>B???#/@??zcrs<A???c??;????>(?x???RB?A,?@D??Y????s???&L?OG??G:????/z?b?qk f???B??SNa???????t?jn@z?+?ryJ???"?C?A?<f?c1?E??f?S?L?sNF??[?P:?G    ? }?X??9QW????6?yrNymGT???n_? ?e???[?]x?}?G??M 1S?%Ef?R{u??k???v? ???Y??h?????o??}JI$?2a~-??5.hz??d3"?????    ?D?z+K??!??X!?    ~yU"'??g???4?V?^?&????V???1S????B?| K.<,??:W?2???:?Xo???k}?t???2k?>??/$B???"z???R?$??[???"D?D????k~ ?U????E)?ez???o??????<??????4???WK??4?o(2-I?m?JFt3??a?U?i??{???r??~-c4???m??R8?2?    ?"?*?ti?G???OS???e??E?B,p?&5t????=7?@?Q??M??rO ?-V??]?NV????H?k??s)?"RB??'????x?*????2?TFw6???i?[S?0?@ ??????C?s?D?_?#=j??dU?n???T?%wL??[?歂)q$ @da?>  S?,?????????Y`QYb ? =Ef?????){V??C???/K?*?Xc}???\?R??g???^?*J??NBF?b??    ??o(??+?[p??%??b????"??????#E?X@~?:J????{?c??i?}??    K?:9??D?W    Se}??O}????l???????`x??S???.?Jk?_}???"A??X????Q6?7"U??I?8?Z?.?Wu??8k?.s??w!?C?k?4??)?j:????v]fIl!6S?S??|Z    ? ?S?'?%I??H?y?8?#q??]H?2V??B?b?j%???u?????jI?$M??%???d?,9??R?>??P?V%?)M?????e???????IU(?uI?i?{6tcX?y?V'?9??}?R@??L??F?????    &?1` O?<?.Xr???[?????~*?Z?B?<b?wU?nG#bLdT??Tm#???_???':??;????l?1l?@?P??U??;?r?(???S??L+?1z?1???W???%??;?u??????D??z1?!<Z!???s4??C?g?he??v?V????L2Tz????^e??\l???Kj9?##??jI?@;?"nMc`8?W?V? ?z    C??R???5?bYJ[4?q???d???/`?

 

加载中
0
KerryLi
KerryLi

原来是那边传过来的本来就是乱码的,通过RC4加密后的所以是乱码

0
-个俗人
-个俗人

需要确认一下发送一端读取出来的编码 是什么编码(在发送端进行调试) 像是没有两端编码没有对应起来

0
进击的企鹅
进击的企鹅

你解码错误了,传过来什么编码,就要用什么解码

0
薯粉1Q84
薯粉1Q84

socket 传输有个大小端的概念,java默认采用大端模式,C++是小端。

http://www.cnblogs.com/LingoXu/p/5235176.html

返回顶部
顶部