【发布时间】:2012-08-22 07:42:53
【问题描述】:
经过 2 天的尝试猜测正确方法后,我放弃了。 很多关于这个主题的问题,但没有任何帮助。
请告诉我我的错误。
任务:将多部分形式(字符串字段和文件)发送到服务器。 服务器等待 ISO-8859-1 编码。
http.Request.Host := fHost;
http.Request.AcceptEncoding := '*';
http.Request.UserAgent := HTTPUserAgent;
http.Request.ContentEncoding := 'ISO-8859-1';
// http.Request.CharSet := 'ISO-8859-1';
if HTTPProxyActive then
http.Request.ProxyConnection := 'close'
else
http.Request.Connection := 'close';
http.Request.ContentType := 'text/plain';
addr := 'https://'+Host+URL;
if ValCount>0 then begin
Stream := TIdMultipartFormDataStream.Create;
for i:=0 to ValCount-1 do begin
if Values[i].Name<>'' then
begin
field := Stream.AddFormField(Values[i].Name, Values[i].Value, 'ISO-8859-1');
// field.Charset := 'ISO-8859-1';
// field.ContentTransfer := '7bit';
end;
if Values[i].Filename<>'' then
Stream.AddFile(Values[i].FileName, Values[i].Value, 'text/plain');
end;
resp := TStringStream.Create;
http.Post(addr, Stream, resp);
st := resp.DataString;
resp.Destroy;
Stream.Destroy;
end
作为帖子的结果我有???????服务器上的顺序。 当我定义字段或请求的字符集时,服务器上出现错误。
请帮助我或缺少什么信息?
更新:我可以使用 UTF-8 获得结果。但是在服务器中我得到了 UTF-8 值,我需要 ISO-8859-1。
UTF-8 解决方案:
field := Stream.AddFormField(Values[i].Name, Values[i].Value, 'UTF-8');
field.ContentTransfer := '8bit';
【问题讨论】:
标签: encoding delphi-2010 indy indy10 multipartform-data