POST 방식으로 IE를 실행시키는 방법

IEPostDataExecute.zip

 

void CIEPostDataExecuteDlg::OnBtnIeExecute()
{
BSTR bstrURL = NULL;
BSTR bstrHeaders = NULL;
CString strURL = _T("http://10.201.2.95:8021/Result.asp");
VARIANT vFlags = {0}, vTargetFrameName = {0}, vPostData = {0}, vHeaders = {0};

HRESULT hr;
if (FAILED(hr = CoInitialize(NULL)))
return;

IWebBrowserApp* pWBApp = NULL;
if (FAILED(hr = CoCreateInstance(CLSID_InternetExplorer, NULL, CLSCTX_SERVER,
IID_IWebBrowserApp, (LPVOID*)&pWBApp)))
goto DoClean;

bstrURL = strURL.AllocSysString();
if (bstrURL == NULL)
goto DoClean;

bstrHeaders = SysAllocString(L"Content-Type: application/x-www-form-urlencoded\r\n");
if (bstrHeaders == NULL)
goto DoClean;

V_VT(&vHeaders) = VT_BSTR;
V_BSTR(&vHeaders) = bstrHeaders;

// POST 데이터를 생서한다.
hr = GeneratePostData(&vPostData);
if (FAILED(hr))
goto DoClean;

hr = pWBApp->Navigate(bstrURL, &vFlags, &vTargetFrameName, &vPostData, &vHeaders);
if (FAILED(hr))
goto DoClean;

pWBApp->put_Width(600);
pWBApp->put_Height(400);