关于网友提出的“ delphi idhttp post 的问题”问题疑问,本网通过在网上对“ delphi idhttp post 的问题”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: delphi idhttp post 的问题
描述:
解决方案1: 参考下这个:
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;
以上介绍了“ delphi idhttp post 的问题”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/3662685.html