我刚写了一个,给你个例子
function Encode(const S: string): string;
var
I: Integer;
Hex: string;
begin
for I := 1 to Length(S) do
case S of
' ': result := Result + '+';
'A'..'Z', 'a'..'z', '*', '@', '.', '_', '-',
'0'..'9', '$', '!', '''', '(', ')':
result := Result + s;
else
begin
Hex := IntToHex(ord(S), 2);
if Length(Hex) = 2 then Result := Result + '%' + Hex else
Result := Result + '%0' + hex;
end;
end;
end;
function StringToVarArray(const S: string): Variant;
begin
Result := Unassigned;
if S <> '' then
begin
Result := VarArrayCreate([0, Length(S) - 1], varByte);
Move(Pointer(S)^, VarArrayLock(Result)^, Length(S));
VarArrayUnlock(Result);
end;
end;
procedure TMainForm.btnPostClick(Sender: TObject);
var
vFlags,
vTarget,
vHeaders,
vPost :OleVariant;
I : Integer;
PostData : string;
begin
vHeaders := 'Content-Type: application/x-www-form-urlencoded'#10#13;
PostData := Encode(Format('tr_id=295&tr_place_id=0&tr_to_nickname=%s&tr_present_num=1',[EditTarget.Text]));
vPost := StringToVarArray(PostData);//一定要这样,vPost是一个SAFEARRAY
WebBrowser1.Navigate('http://www.the9.com/treasure/tr_present.php',vflags,vtarget,vPost,vHeaders);
end;