Programming/Delphi

웹브라우저 POST로 호출하기

통통만두 2010. 6. 30. 15:36
반응형
procedure TfrmMain.NavigateToPost(m_WebBrowser: IWebBrowser2; const URL: String);
const
   _POST_HEADER                     = 'Content-Type: application/x-www-form-urlencoded'+ #10#13#0;
var
   Header                           : OleVariant;
   VPostData                        : OleVariant;
   tmp                              : OleVariant;
   MainURL                          : OleVariant;
   BufferArr                        : TArrayString;
   PostData                         : String;
   Loop                             : Integer;
   T : IWebBrowser;
begin
   try
      Header      := _POST_HEADER;
      BufferArr   := ParceStr(URL, '?');
      MainURL     := BufferArr[0];
      if High(BufferArr) >= 1 then PostData := BufferArr[1];

      MainURL := 'localhost/test.asp';

      VPostData := VarArrayCreate([0, Length(PostData)], varByte);
      for Loop := 0 to Length(PostData)- 1 do
      begin
         VPostData[Loop] := Ord(PostData[Loop+ 1]);
      end;
      VPostData[Length(PostData)] := 0;

      if not Assigned(m_WebBrowser) then
      begin
         m_WebBrowser         := CreateOleObject('Internetexplorer.Application') as IWebBrowser2;
         m_WebBrowser.Visible := True;
      end;

      m_WebBrowser.Navigate2(MainURL, tmp, tmp, VPostData, Header);
      SetWindowPos(m_WebBrowser.HWnd, HWND_TOP, m_WebBrowser.Left, m_WebBrowser.Top, m_WebBrowser.Width, m_WebBrowser.Height, SWP_SHOWWINDOW);
   except
      //
   end;
end;

해당 URL과 웹브라우저 객체를 넘겨받아(없으면 생성한다) Post 방식으로 호출.


반응형