Iwebbrowser2 导航:未提交后期数据

Iwebbrowser2 Navigate: No post-data submitted

本文关键字:数据 提交 导航 Iwebbrowser2      更新时间:2023-10-16

我正在使用IWebbrowser2接口来调用页面并向其提交一些POST数据。IE被打开,页面被调用,但不幸的是没有提交POST数据(PHP服务器上的$_POST数组是空的)。有人能告诉我为什么吗?

主要方法中的相关部分:

BSTR bstrURL2;
bstrURL2 = SysAllocString(L"http://www.mypage.com/");
// Specify a binary Content-Type.
V_BSTR(&vHeaders) = SysAllocString(
  L"Content-Type: application/x-www-form-urlencodedrn" 
  L"Content-Encoding: UTF-8rn");
VARIANT vPostData = {0};
if (Navigate::GetPostData(&vPostData) == NOERROR)
r->Navigate(bstrURL2, &vFlags, &vEmpty, &vPostData, &vHeaders);

GetPostData-method:

HRESULT Navigate::GetPostData(LPVARIANT pvPostData)
{
  HRESULT hr;
  LPSAFEARRAY psa;
  LPCTSTR cszPostData = "username=myusername&password=mypassword";
  UINT cElems;
  LPSTR pPostData;
  cElems = lstrlen(cszPostData);
  if (!pvPostData)
  {
    return E_POINTER;
  }
  VariantInit(pvPostData);
  psa = SafeArrayCreateVector(VT_UI1, 0, cElems);
  if (!psa)
  {
    return E_OUTOFMEMORY;
  }
  hr = SafeArrayAccessData(psa, (LPVOID*)&pPostData);
  memcpy(pPostData, cszPostData, cElems);
  hr = SafeArrayUnaccessData(psa);
  V_VT(pvPostData) = VT_ARRAY | VT_UI1;
  V_ARRAY(pvPostData) = psa;
  return NOERROR;
}

我试图重现您的示例,当我定义vHeader变量的类型时它有效:

// Specify a binary Content-Type.
V_VT(&vHeaders) = VT_BSTR;
V_BSTR(&vHeaders) = SysAllocString(L"Content-Type: application/x-www-form-urlencodedrnContent-Encoding: UTF-8rn");

看这里: https://support.microsoft.com/en-us/kb/167658