LINUX到Windows的编码

LINUX到Windows的编码

本文介绍了LINUX到Windows的编码错误响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个PHP客户端(LINUX)使用Zend_Http_Client访问C#服务器(Windows/MVC 2).

We have a PHP client (LINUX) accessing a C# server (Windows / MVC 2) using Zend_Http_Client.

我们正在尝试设置与请求主体相对应的Authorization标头.

We are trying to set a Authorization header corresponding to the body of the request.

不幸的是,即使在PHP和C#中的编码均为UTF-8,使用C#接收的请求正文也具有一些不同的字符.

Unfortunately, the request body received in C# has some different characters even if the encoding is UTF-8 in both PHP and C#.

尽管如此,C#服务器可以正确设置Request.Files,并且图片可以正常工作.

Although, the C# server can set the Request.Files correctly and the picture will work fine.

此外,一个带有UTF-8编码字符的简单文本文件将毫无问题地通过.

Plus, a simple textfile with UTF-8 encoded characters will go through without any problem.

这是 PHP 请求:

二进制文件部分:

0000000: 0d0a 8950 4e47 0d0a 1a0a 0000 000d 4948  ...PNG........IH
0000010: 4452 0000 0010 0000 0010 0806 0000 001f  DR..............
0000020: f3ff 6100 0000 0467 414d 4100 00af c837  ..a....gAMA....7
0000030: 058a e900 0000 1974 4558 7453 6f66 7477  .......tEXtSoftw
0000040: 6172 6500 4164 6f62 6520 496d 6167 6552  are.Adobe ImageR
0000050: 6561 6479 71c9 653c 0000 029f 4944 4154  eadyq.e<....IDAT
0000060: 38cb a593 eb4b 5361 1cc7 fd3b 76ce 766c  8....KSa...;v.vl
0000070: 0309 6444 2182 8450 7b15 2412 3b9a 0dc5  ..dD!..P{.$.;...
0000080: bc2c 4bd3 ddbd d236 63d8 4c8b 3272 5ec6  .,K....6c.L.2r^.
0000090: 4829 2db3 d46a 734e 6dea d4e6 d694 3271  H)-..jsNm.....2q
00000a0: d951 42cc bde9 42b5 6174 b16f e7ec c54c  .QB...B.at.o...L
00000b0: 1223 7ae0 0b0f 0fcf e7f3 7bae 7100 e2fe  .#z.......{.q...
00000c0: 277f 0c14 f80e 8972 a70f eab3 3d29 4cc6  '......r....=)L.
00000d0: e3fd 61e9 8838 2c75 2532 5267 a23e ddbe  ..a..8,u%2Rg.>..
00000e0: 57b4 ab20 cf9b 4acb 3cc9 219d 4786 9b41  W.. ..J.<.!.G..A
00000f0: 0bfa 96bb a2e9 5c6c 4689 eb18 24bd 5448  ......\lF...$.TH
0000100: d243 d13b 0ad8 aa74 e678 52e4 ea9c 11ce  .C.;...t.xR.....
0000110: d57e d85e 5e83 69ae 321a aeef 58ed 43e3  .~.^^.i.2...X.C.
0000120: 4c15 0ed8 f891 641b 9fde 26c8 f1a4 0833  L.....d...&....3
0000130: dd49 eb1c cc4d ac09 94a1 c25f 02cd cc19  .I...M....._....
0000140: e8d8 94b3 a9f6 9d85 fdf5 3d5c 9caa 80d8  ..........=\....
0000150: 42ae 8baf 93c2 9840 e64e 32a8 c6b2 a295  [email protected].....
0000160: 3998 0355 de53 504c 1742 3155 00f5 5421  9..U.SPL.B1U..T!
0000170: dc6b 8330 7895 70b0 92dc 9e23 48b8 421a  .k.0x.p....#H.B.
0000180: 6282 8c11 31d3 196c 8635 d884 0a5f 3194  b...1..l.5..._1.
0000190: 4fe4 2c98 0fe5 241b 4f3e c6df b8c0 b550  O.,...$.O>.....P
00001a0: 640d 6dcf 1b61 9b6b 447c 3dc9 c404 47ed  d.m..a.kD|=...G.
00001b0: 091b 0f56 6ea3 36a0 81d6 5bc4 ae64 008b  ...Vn.6...[..d..
00001c0: 1fe6 a19a 28c4 d8da 5014 feb1 f91d 6dcf  ....(...P.....m.
00001d0: 2ec1 3051 8cbe 6027 0446 6223 2690 dca7  ..0Q..`'.Fb#&...
00001e0: 36fa 97bb 61f4 ab50 ebd7 e2d3 d78f 51e8  6...a..P......Q.
00001f0: fd97 b731 d832 5b0f b52b 1b7a f769 f407  ...1.2[..+.z.i..
0000200: 3b20 a8f9 5dd0 4331 37e6 9bd0 be70 19ba  ; ..].C17....p..
0000210: 4939 ccbe 6a44 be7d 8ec2 9b3f 3761 797a  I9..jD.}...?7ayz
0000220: 0165 ce2c 6858 414b a00e ed5e 33a8 2a62  .e.,hXAK...^3.*b
0000230: 6b0b a9b7 0406 f940 1aec 2b77 513d 2187  k......@..+wQ=!.
0000240: da7d 1275 d3e5 587a b780 b6d9 0694 0e1e  .}.u..Xz........
0000250: 87c2 7102 3a67 0eec afba 916e 3d0c aa92  ..q.:g.....n=...
0000260: d83a c464 2b5f b88f bd1a b347 8387 cc1d  .:.d+_.....G....
0000270: 548e e641 3b9c 03d5 900c 4a07 170e cec6  T..A;.....J.....
0000280: a3a5 2e18 878a 2150 f3d6 2935 21dc f690  ......!P..)5!...
0000290: 129b 483a be81 8898 dc65 70b0 92d6 8019  ..H:.....ep.....
00002a0: fad1 229c 1b96 a395 dd82 9d85 f5ce 22f0  .."...........".
00002b0: 4b79 1116 a677 7cca 7b1a 489a 3211 2169  Ky...w|.{.H.2.!i
00002c0: 8704 ed7e 337a 5f58 d13b 6f85 c56b 425a  ...~3z_X.;o..kBZ
00002d0: 4b2a 040a 5e88 5211 f4ae 9f89 3a4f 8a28  K*..^.R.....:O.(
00002e0: 03a1 a76a 0846 a0e5 8505 2a5e 98ad c8b0  ...j.F....*^....
00002f0: d153 a584 e8af bff1 5ff3 0b67 d0ac e579  .S......_..g...y
0000300: bad4 6300 0000 0049 454e 44ae 4260 820d  ..c....IEND.B`..
0000310: 0a                                       .

这是C#请求:

二进制文件部分:

0000000: efbf bd50 4e47 0d0a 1a0d 0a20 2020 0d0a  ...PNG.....   ..
0000010: 4948 4452 2020 2010 2020 2010 0806 2020  IHDR   .   ...
0000020: 201f efbf bdef bfbd 6120 2020 0467 414d   .......a   .gAM
0000030: 4120 20ef bfbd efbf bd37 05ef bfbd efbf  A  ......7......
0000040: bd20 2020 1974 4558 7453 6f66 7477 6172  .   .tEXtSoftwar
0000050: 6520 4164 6f62 6520 496d 6167 6552 6561  e Adobe ImageRea
0000060: 6479 71ef bfbd 653c 2020 02ef bfbd 4944  dyq...e<  ....ID
0000070: 4154 38cb a5ef bfbd efbf bd4b 5361 1cef  AT8........KSa..
0000080: bfbd efbf bd3b 76ef bfbd 766c 0309 6444  .....;v...vl..dD
0000090: 21ef bfbd efbf bd50 7b15 2412 3bef bfbd  !......P{.$.;...
00000a0: 0d0a c5bc 2c4b efbf bddd bdef bfbd 3663  ....,K........6c
00000b0: efbf bd4c efbf bd32 725e efbf bd48 292d  ...L...2r^...H)-
00000c0: efbf bdef bfbd 6a73 4e6d efbf bdef bfbd  ......jsNm......
00000d0: efbf bdd6 9432 71ef bfbd 5142 ccbd efbf  .....2q...QB....
00000e0: bd42 efbf bd61 74ef bfbd 6fef bfbd efbf  .B...at...o.....
00000f0: bdef bfbd 4c12 237a efbf bd0b 0f0f efbf  ....L.#z........
0000100: bdef bfbd efbf bd7b efbf bd71 20ef bfbd  .......{...q ...
0000110: efbf bd27 7f0c 14ef bfbd 0eef bfbd 72ef  ...'..........r.
0000120: bfbd 0fef bfbd 3d29 4cef bfbd efbf bdef  ......=)L.......
0000130: bfbd 61ef bfbd 382c 7525 3252 67ef bfbd  ..a...8,u%2Rg...
0000140: 3edd be57 efbf bdef bfbd 20cf 9b4a efbf  >..W...... ..J..
0000150: bd3c efbf bd21 efbf bd47 efbf bdef bfbd  .<...!...G......
0000160: 410b efbf bdef bfbd 5c6c 46ef bfbd efbf  A.......\lF.....
0000170: bd18 24ef bfbd 5448 efbf bd43 efbf bd3b  ..$...TH...C...;
0000180: 0d0a d8aa 74ef bfbd 7852 efbf bdef bfbd  ....t...xR......
0000190: 11ef bfbd efbf bd7e efbf bd5e 5eef bfbd  .......~...^^...
00001a0: 69ef bfbd 321a efbf bdef bfbd 58ef bfbd  i...2.......X...
00001b0: 43ef bfbd 4c15 0eef bfbd efbf bd64 1bef  C...L........d..
00001c0: bfbd efbf bd26 efbf bdef bfbd 0833 efbf  .....&.......3..
00001d0: bd49 efbf bd1c efbf bd4d efbf bd09 efbf  .I.......M......
00001e0: bdef bfbd efbf bd5f 02ef bfbd efbf bd19  ......._........
00001f0: efbf bdd8 94ef bfbd efbf bdef bfbd efbf  ................
0000200: bdef bfbd efbf bdef bfbd 3d5c efbf bdef  ..........=\....
0000210: bfbd efbf bdef bfbd 42ef bfbd efbf bdef  ........B.......
0000220: bfbd efbf bdc2 9840 efbf bd4e 32ef bfbd  [email protected]...
0000230: c6b2 efbf bdef bfbd 39ef bfbd 0355 efbf  ........9....U..
0000240: bd53 504c 1742 3155 20ef bfbd 5421 efbf  .SPL.B1U ...T!..
0000250: bd6b efbf bd30 78ef bfbd 70ef bfbd efbf  .k...0x...p.....
0000260: bddc 9e23 48ef bfbd 421a 62ef bfbd efbf  ...#H...B.b.....
0000270: bd11 31ef bfbd 196c efbf bd35 d884 0d0a  ..1....l...5....
0000280: 5f31 efbf bd4f efbf bd2c efbf bd0f efbf  _1...O...,......
0000290: bd24 1b4f 3eef bfbd dfb8 efbf bdef bfbd  .$.O>...........
00002a0: 5064 0d0a 6def bfbd 1b61 efbf bd6b 447c  Pd..m....a...kD|
00002b0: 3def bfbd efbf bd04 47ef bfbd 091b 0f56  =.......G......V
00002c0: 6eef bfbd 36ef bfbd efbf bdef bfbd 5bc4  n...6.........[.
00002d0: ae64 20ef bfbd 1fe6 a19a 28ef bfbd efbf  .d .......(.....
00002e0: bdef bfbd 5014 efbf bdef bfbd efbf bd1d  ....P...........
00002f0: 6def bfbd 2eef bfbd 3051 efbf bdef bfbd  m.......0Q......
0000300: 6027 0446 6223 26ef bfbd dca7 36ef bfbd  `'.Fb#&.....6...
0000310: 61ef bfbd efbf bd50 efbf bdef bfbd efbf  a......P........
0000320: bdef bfbd d78f 51ef bfbd efbf bd31 efbf  ......Q......1..
0000330: bd32 5b0f efbf bd2b 1b7a efbf bd69 efbf  .2[....+.z...i..
0000340: bd07 3b20 efbf bdef bfbd 5def bfbd 4331  ..; ......]...C1
0000350: 37ef bfbd d0be 7019 efbf bd49 39cc be6a  7.....p....I9..j
0000360: 44ef bfbd 7def bfbd c29b 3f37 6179 7a01  D...}.....?7ayz.
0000370: 65ef bfbd 2c68 5841 4bef bfbd 0eef bfbd  e...,hXAK.......
0000380: 5e33 efbf bd2a 626b 0bef bfbd efbf bd04  ^3...*bk........
0000390: 06ef bfbd 401a efbf bd2b 7751 3d21 efbf  ....@....+wQ=!..
00003a0: bdef bfbd 7d12 75ef bfbd efbf bd58 7aef  ....}.u......Xz.
00003b0: bfbd efbf bdef bfbd efbf bd06 efbf bd0e  ................
00003c0: 1eef bfbd efbf bd71 023a 670e ecaf baef  .......q.:g.....
00003d0: bfbd 6e3d 0cef bfbd efbf bdef bfbd 3aef  ..n=..........:.
00003e0: bfbd 642b 5fef bfbd efbf bdef bfbd 1aef  ..d+_...........
00003f0: bfbd 47ef bfbd efbf bdef bfbd 1d54 efbf  ..G..........T..
0000400: bdef bfbd 413b efbf bd03 d590 0c4a 0717  ....A;.......J..
0000410: 0eef bfbd c6a3 efbf bd2e 18ef bfbd efbf  ................
0000420: bd21 50ef bfbd efbf bd29 3521 efbf bdef  .!P......)5!....
0000430: bfbd efbf bd12 efbf bd48 3aef bfbd efbf  .........H:.....
0000440: bdef bfbd efbf bdef bfbd 6570 efbf bdef  ..........ep....
0000450: bfbd d680 19ef bfbd efbf bd22 efbf bd1b  ..........."....
0000460: efbf bdef bfbd efbf bddd 82ef bfbd efbf  ................
0000470: bdef bfbd efbf bd22 efbf bd4b 7911 16ef  ......."...Ky...
0000480: bfbd 777c efbf bd7b 1a48 efbf bd32 1121  ..w|...{.H...2.!
0000490: 69ef bfbd 04ef bfbd 7e33 7a5f 58ef bfbd  i.......~3z_X...
00004a0: 3b6f efbf bdef bfbd 6b42 5a4b 2a04 0d0a  ;o......kBZK*...
00004b0: 5eef bfbd 5211 efbf bdef bfbd efbf bdef  ^...R...........
00004c0: bfbd 3a4f efbf bd28 03ef bfbd efbf bd6a  ..:O...(.......j
00004d0: 0846 efbf bdef bfbd 052a 5eef bfbd efbf  .F.......*^.....
00004e0: bdc8 b0ef bfbd 53ef bfbd efbf bde8 afbf  ......S.........
00004f0: efbf bd5f efbf bd0b 67d0 acef bfbd 79ef  ..._....g.....y.
0000500: bfbd efbf bd63 2020 2020 4945 4e44 efbf  .....c    IEND..
0000510: bd42 60ef bfbd 0d0a                      .B`.....

对此有任何线索吗?

推荐答案

UTF-8旨在对Unicode字符集进行编码.通常,它不能用于编码任意二进制数据,因为(取决于实现方式)当二进制数据表示非法Unicode字符时,它可能会出现异常.

UTF-8 is designed to encode the Unicode character set. It can't in general be used to encode arbitrary binary data, because (depending on the implementation) it may misbehave when the binary data represents illegal Unicode characters.

您需要以未编码的二进制形式,或使用诸如Base64之类的编码(用于任意二进制数据)将请求从PHP传递到C#程序.

You need to pass the request from PHP to your C# program in unencoded binary form, or in an encoding such as Base64 which is designed for arbitrary binary data.

这篇关于LINUX到Windows的编码错误响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 22:38