2日間正しい方法を推測しようとした後、私はあきらめました。件名に関する多くの質問がありますが、何も役に立ちません。
私の間違いを見せてください。
タスク: multipart-form (文字列フィールドとファイル) をサーバーに送信します。サーバーは 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';