导航:
论坛 -> DELPHI技术
斑竹:liumazi,sephil
作者:
2017/8/19 23:22:48
标题:
utf8解码从D7编导Delphi10.2要怎么改啊
浏览:2206
加入我的收藏
楼主:
之前在D7上是这样写的 ProcessTxt.Lines.Add(UTF8Decode(IdHTTP1.Response.RawHeaders.Text)); 那么在delphi10.2后要怎么写啊?UTF8Decode是不行的
----------------------------------------------
只会简单使用,并未精通深入
作者:
2017/8/20 12:39:19
1楼:
去掉UTF8Decode试试。Delphi2009以上会自动解码吧。
----------------------------------------------
http://mcool.appinn.me/
作者:
2017/8/20 15:45:09
2楼:
但是,IdHTTP1.Response.RawHeaders.Text里面含有中文,所以中文部分是乱码,要如何转换?
----------------------------------------------
只会简单使用,并未精通深入
作者:
2017/8/20 18:41:04
3楼:
我当时从D7转到D2009都是这么干的,不会产生乱码。
----------------------------------------------
http://mcool.appinn.me/
作者:
2017/8/20 19:29:10
4楼:
我测试代码为下载一个文件,此文件名处于返回的http header中,文件名含中文,需要得到这个文件名 首先在D7中测试,代码为: Str:=BDC.SysSite+'download/product'; jo := SO('{"productid":"'+productid+'","type":"'+TypeName+'"}'); TStream := TMemoryStream.Create; TJ := TStringList.Create; TJ.Append(utf8Encode(jo.AsString)); IdHTTP1.Post(Str,TJ,TStream); TJ.Free; ProcessTxt.Lines.Add(UTF8Decode(IdHTTP1.Response.RawHeaders.Text)); 返回的头部信息为 Server: nginx/1.4.6 (Ubuntu) Date: Sun, 20 Aug 2017 11:22:47 GMT Content-Type: application/zip Content-Length: 273003 Connection: close Access-Control-Allow-Credentials: true Access-Control-Allow-Headers: Content-Type, Content-Range, Content-Disposition, Content-Description, x-requested-with, content-type, reqUserId, reqUserSession, bizCode, reqBizGroup, reqUserSession, bizsign, timestamp, token, ManageGroupType, ManageGroupId, reqtype, fileMd5 Access-Control-Allow-Methods: POST Access-Control-Allow-Methods: GET Access-Control-Allow-Methods: DELETE Access-Control-Allow-Methods: PUT Access-Control-Allow-Origin: * Content-Disposition: attachment;filename=XC.2017.008.003_净水器(T3平台新增 Filemd5: 983c6fda8a3542123d8131f06a0d9a29 ==========获取成功,得到文件名========== ========== 接下来在10.2的IDE里,代码 jo:=SO(); jo.S['productid']:=productid; jo.S['type']:=dltypeTxt.Value; MS := TMemoryStream.Create; stream := TStringStream.Create(jo.AsString, TEncoding.UTF8); FWSInfo.IdHTTP1.Post( BDC.SysSite+'download/product', stream,MS); stream.Free; dllogTxt.Lines.Add(FWSInfo.IdHTTP1.Response.RawHeaders.Text); 返回的头部信息为: Server: nginx/1.4.6 (Ubuntu) Date: Sun, 20 Aug 2017 11:14:03 GMT Content-Type: application/zip Content-Length: 273003 Connection: close Access-Control-Allow-Credentials: true Access-Control-Allow-Headers: Content-Type, Content-Range, Content-Disposition, Content-Description, x-requested-with, content-type, reqUserId, reqUserSession, bizCode, reqBizGroup, reqUserSession, bizsign, timestamp, token, ManageGroupType, ManageGroupId, reqtype, fileMd5 Access-Control-Allow-Methods: POST Access-Control-Allow-Methods: GET Access-Control-Allow-Methods: DELETE Access-Control-Allow-Methods: PUT Access-Control-Allow-Origin: * Content-Disposition: attachment;filename=XC.2017.008.003������������T3������������ Filemd5: 983c6fda8a3542123d8131f06a0d9a29 ==========获取失败========== 所以中文要如何转换
----------------------------------------------
只会简单使用,并未精通深入
作者:
2017/8/21 8:50:16
5楼:
试试HTTPDecode,是不是编码的问题,引用单元HttpApp。 要么给大家一个测试环境,可以调试。
----------------------------------------------
Delphi爱好者。
作者:
2017/8/21 9:38:12
6楼:
没法提供调试环境啊,因为网站是客户的额,且限定了IP地址,
----------------------------------------------
只会简单使用,并未精通深入
作者:
2017/8/21 9:39:16
7楼:
乱码是这样的
----------------------------------------------
只会简单使用,并未精通深入
作者:
2017/8/21 14:04:48
8楼:
我的问题是,在DelphiXE10.2内 IdHTTP1.Response.RawHeaders.Text这个http的头部信息中如果含有中文要如何才能正确显示
----------------------------------------------
只会简单使用,并未精通深入
作者:
2017/9/5 9:11:37
9楼:
FWSInfo.IdHTTP1.Post( BDC.SysSite+'download/product', stream,MS);最后参数加IndyTextEncoding(TEncoding.UTF8)
----------------------------------------------
-
作者:
2017/9/5 23:39:08
10楼:
ProcessTxt.Lines.Add(UTF8ToString(IdHTTP1.Response.RawHeaders.Text));
----------------------------------------------
-
作者:
2017/9/6 19:42:17
11楼:
9 楼可能是正解,或者按这个思路来 idny 新版本 都支持 编码选择。建议楼主多看看控件属性和方法参数。编码选择是网络控件必不可少的。
----------------------------------------------
(C)(P)Flying Wang
作者:
2017/9/6 19:47:49
12楼:
直接不要就行了,xe也有一个encode的单元,里面有类似的函数
----------------------------------------------
-
作者:
2017/9/7 14:43:57
14楼:
stlont (龙头老大) 你的这个方法返回的都是这样的 XC.2017.008.003??????????T3??????????
----------------------------------------------
只会简单使用,并未精通深入
作者:
2017/9/7 14:44:16
15楼:
mousesoft (MouseSoft) 能具体点吗?
----------------------------------------------
只会简单使用,并未精通深入
作者:
2017/9/7 15:01:47
16楼:
betterlihua (lihua) 最后参数加IndyTextEncoding(TEncoding.UTF8), 是这样的吗? FWSInfo.IdHTTP1.Post( strurl, stream,MS,IndyTextEncoding(TEncoding.UTF8)); 这样的不行[dcc32 Error] download_product.pas(106): E2250 There is no overloaded version of 'Post' that can be called with these arguments ms是一个需要下载的文件 MS.SaveToFile('files.zip');
----------------------------------------------
只会简单使用,并未精通深入
作者:
2017/9/7 15:05:01
17楼:
wang_80919 (Flying Wang) 这类的资料哪里能找到呀?
----------------------------------------------
只会简单使用,并未精通深入
作者:
2017/9/7 15:05:47
18楼:
好好看人家 INDY 的源码。 你这种问题,太低级。
----------------------------------------------
(C)(P)Flying Wang
作者:
2017/9/7 20:53:05
19楼:
不懂就问么,搞明白了才是最实在的,感觉没啥低级高级的,一家之言,不喜勿怪。我还以为有专门讲indy的电子书的
----------------------------------------------
只会简单使用,并未精通深入
作者:
2017/9/8 1:15:37
20楼:
indy初始化可指定GBK或GB2312等编码, 要和访问的网站一致
----------------------------------------------
-
作者:
2017/9/12 20:31:08
21楼:
stlont (龙头老大) 具体是哪个参数啊?
----------------------------------------------
只会简单使用,并未精通深入
作者:
2017/9/13 12:34:20
22楼:
具体去看源码,一家之言,爱看不看。
----------------------------------------------
(C)(P)Flying Wang
作者:
2017/9/14 0:24:31
23楼:
IdHTTP.Request.AcceptCharSet
----------------------------------------------
-