Delphi - WebBrowser载入自定义HTML内容并显示

use  
  Winapi.ActiveX;   //调用IPersistStreamInit类

procedure TForm1.Button2Click(Sender: TObject);  
var  
  PostList: TStringList;  
  Response, StrStream: TStringStream;  
  ResultString: string;  
begin  
  // 注册  
  PostList := TStringList.Create;  
  Response := TStringStream.Create('', TEncoding.UTF8);  
  try  
    IdHTTP1.HandleRedirects := True;  
  
    PostList.Add('forward=');  
    PostList.Add('jumpurl=http://www.hualongxiang.com/index.php');  
    PostList.Add('step=2');  
    PostList.Add('pwuser=' + Trim(Edit1.Text));  
    PostList.Add('lgt=0');  
    PostList.Add('pwpwd=' + Trim(Edit2.Text));  
    PostList.Add('cktime=31536000');  
  
    ResultString := IdHTTP1.Post('http://jia.hualongxiang.com/register.php', PostList);  
  
    if Pos('200 OK', IdHTTP1.ResponseText) > 0 then  
    begin  
      	Memo1.Lines.Add(ResultString);  
   	// 以下代码为WebBrowser显示自定义HTML内容  
        WebBrowser1.Navigate('about:blank'); // 必要  
        StrStream := TStringStream.Create(ResultString);  
        try  
          StrStream.Position:=0;  
          (WebBrowser1.Document as IPersistStreamInit).Load(TStreamadapter.Create(StrStream)); // 关键语句  
        finally  
          StrStream.Free;  
        end;  
    	// 至此结束  
    end;  
  
  finally  
    PostList.Free;  
    Response.Free;  
  end;  
end;

你可能感兴趣的:(html,Delphi,idhttp)