procedure THttpPostForm.PostButtonClick(Sender: TObject);
var
Data : String;
begin
Data := 'FirstName=' + UrlEncode(Trim('test')) + '&' +
'LastName=' + UrlEncode(Trim('test123')) + '&' +
'Submit=';
HttpCli1.SendStream := TMemoryStream.Create;
HttpCli1.SendStream.Write(Data[1], Length(Data));
HttpCli1.SendStream.Seek(0, 0);
HttpCli1.RcvdStream := TMemoryStream.Create;
HttpCli1.URL := Trim('URL');
HttpCli1.PostAsync;
end;
在RequestDone事件中接收和释放对象
procedure THttpPostForm.HttpCli1RequestDone(
Sender : TObject;
RqType : THttpRequest;
ErrCode : Word);
var
Data : String;
begin
HttpCli1.SendStream.Free;
HttpCli1.SendStream := nil;
if ErrCode <> 0 then //有异常
begin
HttpCli1.RcvdStream.Free;
HttpCli1.RcvdStream := nil;
Exit;
end;
if HttpCli1.StatusCode <> 200 then //返回错误
begin
HttpCli1.RcvdStream.Free;
HttpCli1.RcvdStream := nil;
Exit;
end;
HttpCli1.RcvdStream.Seek(0, 0);
SetLength(Data, HttpCli1.RcvdStream.Size);
HttpCli1.RcvdStream.Read(Data[1], Length(Data));
end;
1 条评论
请教一下,UrlEncode是函数吗?
编译时出现如下错误
[Error] Unit1.pas(36): Undeclared identifier: 'UrlEncode'
[Error] Unit1.pas(37): Incompatible types
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'