POST 방식으로 IE를 실행시키는 방법 DarkKaiser, 2008년 3월 27일2023년 9월 6일 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); pWBApp->put_Visible(VARIANT_TRUE); DoClean: if (bstrURL != NULL) SysFreeString(bstrURL); if (bstrHeaders != NULL) SysFreeString(bstrHeaders); VariantClear(&vPostData); if (pWBApp) pWBApp->Release(); CoUninitialize(); } HRESULT CIEPostDataExecuteDlg::GeneratePostData(LPVARIANT lpvPostData) { if (!lpvPostData) return E_POINTER; CString strPostData = _T("name=test_id&age=test_pwd&sys_tp="); LPCTSTR cszPostData = (LPCTSTR)strPostData; UINT cElems = lstrlen(cszPostData); VariantInit(lpvPostData); LPSAFEARRAY psa = SafeArrayCreateVector(VT_UI1, 0, cElems); if (!psa) return E_OUTOFMEMORY; LPSTR pPostData; SafeArrayAccessData(psa, (LPVOID*)&pPostData); memcpy(pPostData, cszPostData, cElems); SafeArrayUnaccessData(psa); V_VT(lpvPostData) = VT_ARRAY|VT_UI1; V_ARRAY(lpvPostData) = psa; return NOERROR; } C/C++/VC++ IEPOST