如何读取IdHTTP1.Response.RawHeaders.Text中含有中文的值,utf8编码 |
尚未結案
|
ken0137
一般會員 發表:1 回覆:1 積分:0 註冊:2009-01-18 發送簡訊給我 |
网站返回的IdHTTP1.Response.RawHeaders.Text是utf8编码的,之前使用的是D7,读取到的值里面含有中文能正常解码,但是现在换成了XE10.2了,就不知道应该如何转换了,求教
之前:D7 indy superjson 现在:XE10.2 indy superjson 我测试代码为下载一个文件,此文件名处于返回的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.003T3 Filemd5: 983c6fda8a3542123d8131f06a0d9a29 ==========获取失败========== 所以中文要如何转换 |
dennieschang
一般會員 發表:2 回覆:24 積分:15 註冊:2002-03-13 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |