none
PIE (Web Browser Control)problems: IWebBrowser::Navigate(2) never sucessfully send post request. RRS feed

  • Question

  • Hi there,
        I used a web browser control in my WM6 project. I could send a GET quest via IWebBrowser2::Navigate method, however, I never successfully sent a POST request.
        i checked the code again and again and I didn't found an error. I thought maybe I use wrong way to send POST? But when I tested exactly the same code on my windows vista I found it can work!!! This just make me crazy. Could anybody give me some hints?
    The following is my code which I have omitted all unnecessary part.
        RECT rectClient;
    GetClientRect(&rectClient);
    CoInitializeEx(NULL, COINIT_MULTITHREADED);

    // create browser control
    BOOL ret = m_browser.CreateControl(CLSID_WebBrowser,
    NULL,
    WS_VISIBLE | WS_BORDER | WS_CHILD,
    rectClient,
    this,
    AFX_IDW_PANE_FIRST);

    LPUNKNOWN lpunk = m_browser.GetControlUnknown();
    HRESULT hr = lpunk->QueryInterface(IID_IWebBrowser2, (void**)&m_pBrowser);
    BSTR url = SysAllocString(L"http://localhost/");

    // post data
    VARIANT vPostData = {0};
    LPSAFEARRAY psa;
    char* postData = "username=name&password=word";
    UINT num = strlen(postData);
    VariantInit(&vPostData);
    psa = SafeArrayCreateVector(VT_UI1, 0, num);

    char* pPostData = NULL ;
    hr = SafeArrayAccessData(psa, (LPVOID*)&pPostData);
    memcpy(pPostData, postData, num);
    hr = SafeArrayUnaccessData(psa);
    V_VT(&vPostData) = VT_ARRAY | VT_UI1;
    V_ARRAY(&vPostData) = psa;

    //headers
    VARIANT vHeader = {0};
    VariantInit(&vHeader);
    BSTR bstrHeaders = SysAllocString(
    L"Content-Type: application/x-www-form-urlencoded\r\n");
    V_VT(&vHeader) = VT_BSTR;
    V_BSTR(&vHeader) = bstrHeaders;

    m_pBrowser->put_Visible(VARIANT_TRUE);
    m_pBrowser->put_AddressBar(VARIANT_TRUE);
    m_pBrowser->put_StatusBar(VARIANT_TRUE);

    VARIANT vUrl ={0};
    VariantInit(&vUrl);
    V_VT(&vUrl) = VT_BSTR;
    V_BSTR(&vUrl)= url;
    hr = m_pBrowser->Navigate2(&vUrl,NULL,NULL,&vPostData,&vHeader);
    • Edited by Chen_Zhuo Tuesday, June 16, 2009 3:39 AM
    Sunday, June 14, 2009 3:09 PM

All replies

  • I guess maybe I mistook the usage of Postdata, but I can't find a right one ...
    BY the way, my platform is windows mobile 6 professional edition.
    Tuesday, June 16, 2009 3:42 AM
  • Still no answer?
    I'm disappointed.
    Monday, June 22, 2009 2:45 AM
  • UPUP
    Friday, July 3, 2009 1:53 AM
  • Actually, I'm also experiencing the same problem, on both WM 5/WM 6. The post logic looks correct, I've copied the basic structure used both in the Microsoft knowledge bases (http://support.microsoft.com/kb/815722,  http://support.microsoft.com/kb/174923,  http://support.microsoft.com/kb/280509), and I've given up a week of my life trying to make this work correctly. Unfortunately the application I'm working with does not correctly extract GET parameters, so I have no option but to use POST, but regardless of how I create the post data VARIANT, in the OnBeforeNavigate2 event the post data VARIANT ALWAYS has a type of VT_ERROR.

    I've not found any particular comments indicating that its impossible to do a Navigate2 using the Pocket IE object model: if this is the case could anyone with a little knowledge share, or if not could anyone who's had success using C++ (I'm in VS 2005, writing a WTL application) point out where the deviations between what's recommended and what actually works?

    Thanks,
    Imperial.
    Saturday, December 19, 2009 9:32 PM
  • I would suggest opening a Service Request at Microsoft Technical Support in order to further troubleshoot the issue: if the control is not behaving as expected and documented, then it may be that there's a bug underlying it that the dev team should address. Opening a Service Request is simple and it may also be that you're already eligible for it depending on your contract (for example Premier\Partner\MSDN Subscription). If you never did it, then my following post may help: http://blogs.msdn.com/raffael/archive/2008/05/14/get-what-you-paid-for.aspx.

    HTH!


    Thanks,
    ~raffaele
    http://blogs.msdn.com/raffael

    This posting is provided 'as is' with no warranties and confers no rights.
    Wednesday, December 30, 2009 3:43 PM
  • Hi,

    I'm also having trouble with CreateControl. However, in my case the control is not even rendered.

    Did it render in the standard Windows Mobile emulator?

    Here's a minimal example:

    http://social.msdn.microsoft.com/Forums/en-US/vssmartdevicesnative/thread/a5e9dbc1-7ac5-4d85-b71a-bcbd94e32019

    If it did render for you, can you spot the difference with your code and perhaps share your example as well?

    Best,

    MS

    Saturday, May 14, 2011 8:59 AM