5,928
社区成员




postParam:=TStringList.Create;
response:=TStringStream.Create('');
postParam.Add('Submit=登 录');
idHttp.Post('http://www.abc.com,postParam,
response);
type
ISO8859String = type AnsiString(1252);
GB2312String = type AnsiString(936);
function URIParamsEncode(const ASrc: RawByteString): RawByteString;
const
UnsafeChars = ['*', '#', '%', '<', '>', '[', ']'];
ASCIIChars = [#$21..#$7f];
AnsiHex : array[0..15]of AnsiChar = '0123456789ABCDEF';
var
i, len : Integer;
b : Byte;
c : AnsiChar;
sBuff : RawByteString;
pSrc, pDst : PAnsiChar;
begin
len := Length(ASrc);
if(ASrc[len]='&')then Dec(len);
SetLength(sBuff, len*3);
pSrc := Pointer(ASrc);
pDst := Pointer(sBuff);
for i := 0 to Len - 1 do
begin
c := pSrc[i];
if((c in UnsafeChars)or(not(c in ASCIIChars)))then
begin
b := Byte(c);
pDst[0] := '%';
pDst[1] := AnsiHex[b shr 4];
pDst[2] := AnsiHex[b and $f];
Inc(pDst, 3);
end else
begin
pDst^ := c;
Inc(pDst);
end;
end;
pSrc := Pointer(sBuff);
SetString(Result, pSrc, pDst-pSrc);
end;
var
lstPost : TStringList;
stmTmp : TMemoryStream;
sI8859 : ISO8859String;
sGb2312 : GB2312String;
begin
lstPost := TStringList.Create;
stmTmp := TMemoryStream.Create;
try
lstPost.Add('mobile='+Edit1.Text);
lstPost.Add('action=mobile');
lstPost.Add('test=测 试');
IdHTTP1.Request.ContentType := 'application/x-www-form-urlencoded';
sGb2312 := URIParamsEncode( GB2312String(StringReplace(
lstPost.Text, #13#10, '&', [rfReplaceAll] )) );
stmTmp.Write(sGb2312[1], Length(sGb2312));
stmTmp.Position := 0;
sI8859 := ISO8859String(IdHTTP1.Post(URLPost, stmTmp));
SetString(sGb2312, PAnsiChar(sI8859), Length(sI8859));
Memo1.Text := string(sGB2312);
finally
stmTmp.Free;
lstPost.Free;
end;