delphi xe10 indy 表单post 方法, utf8编码


// 亲测 不会乱码
var CuId,ModelId,sid : Integer; lmsg : string; Idc: TIdHTTP; Ptxt : string; postJson,jo :ISuperObject; rst : Boolean; lmfd: TIdMultiPartFormDataStream; responseStream: TStringStream; begin Result := False; try lmfd := TIdMultiPartFormDataStream.Create; responseStream := TStringStream.Create(); lmfd.AddFormField('cuid',vcuid,'UTF-8').ContentTransfer := '8bit' ; lmfd.AddFormField('type',vtype,'UTF-8').ContentTransfer := '8bit'; Idc := TIdHTTP.Create(nil); Idc.ReadTimeout := 60000; Idc.ConnectTimeout := 60000; // Idc.Request.ContentType := 'application/json'; Idc.Request.ContentType := 'application/x-www-form-urlencoded'; Ptxt := ''; try try idc.Post(gqrurl,lmfd,responseStream); ptxt := responseStream.DataString; if ptxt <> '' then begin jo := so(ptxt); rst := jo.B['status']; if rst then begin Result := True; vmsg := jo.S['data']; end; end; except on e: exception do begin vmsg := e.Message; end; end; finally Idc.Free; end; FreeAndNil(responseStream); FreeAndNil(lmfd); except on e: exception do begin if responseStream <> nil then FreeAndNil(responseStream); if lmfd <> nil then FreeAndNil(lmfd); end; end;

  

原文地址:https://www.cnblogs.com/iwana/p/13091211.html