我需要使用delph 10.2获取IdHTTP1.Response.RawHeaders.Text内的Content-Disposition字段的值,但是此值是含有中文的,在10.2的平台上不知道如何转化,求教
我测试代码为下载一个文件,此文件名处于返回的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
==========获取失败==========
所以中文要如何转换