🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internet.web
4 messages
4 total messages Started by Mischa Simmonds Tue, 07 Aug 2007 13:32
WebBrowser Navigate Post problems!
#232
Author: Mischa Simmonds
Date: Tue, 07 Aug 2007 13:32
21 lines
1762 bytes
I am trying to use either the Navigate or Navigate2 methods within 
IWebBrowser2 but even though I provide post data and the additional 
header data I can still only send the equivalent of a GET command (ie: 
just load the URL but not post any data with it)

My code is something like this...

AnsiString URL="http://www.somewhere.com";
AnsiString Post="name=Mischa&Country=Australia";
_di_IWebBrowser2 CppWebBrowser->Navigate2(URL,"","",Post,"Content-Type: 
application/x-www-form-urlencoded\r\n");

It looks like Post should be a Variant of sorts, but I just can't work 
it out.

I have looked at http://msdn2.microsoft.com/en-us/library/aa752127.aspx 
(IWebBrowser2::Navigate/Navigate2 Methods), and also tried to use the 
ideas expressed in http://dn.codegear.com/en/article/27519 but get the 
same result.

Any ideas?
Re: WebBrowser Navigate Post problems!
#233
Author: Remy Lebeau (TeamB)
Date: Tue, 07 Aug 2007 17:20
42 lines
2386 bytes
"Mischa Simmonds" <mischa1.BanSpam@informationdesign.BanSpam.com.au> wrote
in message news:46b87478$1@newsgroups.borland.com...

> My code is something like this...

That code shouldn't even be able to compile, let alone run.  Each of the
parameters of TCppWebBrowser::Navigate2() expect a pointer to a TVariant,
but you are not constructing any TVariant instances at all.  And it is also
unclear whether you are actually trying to call the
TCppWebBrowser::Navigate2() method or the IWebBrowser2::Navigate2() method,
for that matter.

Try this instead:

    AnsiString asPostData = "name=Mischa&Country=Australia";

    LPSAFEARRAY psa = SafeArrayCreateVector(VT_UI1, 0, asPostData.Length());
    if( psa )
    {
        void *pvdata = NULL;
        SafeArrayAccessData(psa, &pvdata);
        memcpy(pvdata, asPostData.c_str(), asPostData.Length());
        SafeArrayUnaccessData(psa);

        TVariant vPostData(psa);
        TVariant vURL = AnsiString("http://www.somewhere.com");
        TVariant vContentType = AnsiString("Content-Type:
application/x-www-form-urlencoded\r\n");

        CppWebBrowser->Navigate2(&vURL, TNoParam(), TNoParam(), &vPostData,
&vContentType);
    }


> I have ... also tried to use the ideas expressed in
> http://dn.codegear.com/en/article/27519 but get the same result.

The code you showed is not doing anything that article says to do.


Gambit
Re: WebBrowser Navigate Post problems!
#234
Author: Mischa Simmonds
Date: Thu, 09 Aug 2007 02:03
83 lines
3576 bytes
Thank you, thank you Remy!

It works!

However, I had to remove the referencing operators (&) from the 
Navigate2 function for it to work (no data was being sent at all). Also, 
I used "TVariant vFlags = {0};" instead of "TNoParam() ", as I got the 
error, "E2064 Cannot initialize 'OleVariant &' with 'TNoParam' " on 
compilation.

Here is my final code....

void WebPostData(_di_IWebBrowser2 CppWebBrowser, AnsiString sURL, 
AnsiString sPostData)
{
    LPSAFEARRAY psa = SafeArrayCreateVector(VT_UI1, 0, sPostData.Length());
    if( psa )
    {
        void *pvdata = NULL;
        SafeArrayAccessData(psa, &pvdata);
        memcpy(pvdata, sPostData.c_str(), sPostData.Length());
        SafeArrayUnaccessData(psa);
        TVariant vPostData(psa);
        TVariant vFlags = {0}, vTargetFrameName={0};
        TVariant vURL=sURL;
        TVariant vContentType = 
AnsiString("Content-Type:application/x-www-form-urlencoded\r\n");
        CppWebBrowser->Navigate2(vURL, vFlags, vTargetFrameName, 
vPostData,vContentType);
    }
}



Remy Lebeau (TeamB) wrote:
> "Mischa Simmonds" <mischa1.BanSpam@informationdesign.BanSpam.com.au> wrote
> in message news:46b87478$1@newsgroups.borland.com...
>
>   
>> My code is something like this...
>>     
>
> That code shouldn't even be able to compile, let alone run.  Each of the
> parameters of TCppWebBrowser::Navigate2() expect a pointer to a TVariant,
> but you are not constructing any TVariant instances at all.  And it is also
> unclear whether you are actually trying to call the
> TCppWebBrowser::Navigate2() method or the IWebBrowser2::Navigate2() method,
> for that matter.
>
> Try this instead:
>
>     AnsiString asPostData = "name=Mischa&Country=Australia";
>
>     LPSAFEARRAY psa = SafeArrayCreateVector(VT_UI1, 0, asPostData.Length());
>     if( psa )
>     {
>         void *pvdata = NULL;
>         SafeArrayAccessData(psa, &pvdata);
>         memcpy(pvdata, asPostData.c_str(), asPostData.Length());
>         SafeArrayUnaccessData(psa);
>
>         TVariant vPostData(psa);
>         TVariant vURL = AnsiString("http://www.somewhere.com");
>         TVariant vContentType = AnsiString("Content-Type:
> application/x-www-form-urlencoded\r\n");
>
>         CppWebBrowser->Navigate2(&vURL, TNoParam(), TNoParam(), &vPostData,
> &vContentType);
>     }
>
>
>   
>> I have ... also tried to use the ideas expressed in
>> http://dn.codegear.com/en/article/27519 but get the same result.
>>     
>
> The code you showed is not doing anything that article says to do.
>
>
> Gambit
>
>
>   
Re: WebBrowser Navigate Post problems!
#235
Author: Remy Lebeau (TeamB)
Date: Thu, 09 Aug 2007 02:37
54 lines
2870 bytes
"Mischa Simmonds" <mischa1.BanSpam@informationdesign.BanSpam.com.au> wrote
in message news:46ba75fc@newsgroups.borland.com...

> However, I had to remove the referencing operators (&) from the
> Navigate2 function for it to work (no data was being sent at all).

You need to use the '&' operator.  Navigate2() is expecting pointers:

    HRESULT Navigate2(VARIANT *URL, VARIANT *Flags, VARIANT
*TargetFrameName, VARIANT *PostData, VARIANT *Headers);

> I used "TVariant vFlags = {0};" instead of "TNoParam() "

TNoParam() is the proper way to pass an empty variant for an optional
parameter.  It initializes a TVariant whose vt member is set to VT_ERROR and
scode member is set to DISP_E_PARAMNOTFOUND.  Those values are a requirement
for optional parameters, but you are not doing that in your code.

> I got the error, "E2064 Cannot initialize 'OleVariant &' with 'TNoParam' "
> on compilation.

Navigate2() does not use OleVariant.

> Here is my final code....

Try this instead:

    void WebPostData(_di_IWebBrowser2 CppWebBrowser, const AnsiString &sURL,
const AnsiString &sPostData)
    {
        LPSAFEARRAY psa = SafeArrayCreateVector(VT_UI1, 0,
sPostData.Length());
        if( psa )
        {
            void *pvdata = NULL;
            SafeArrayAccessData(psa, &pvdata);
            memcpy(pvdata, sPostData.c_str(), sPostData.Length());
            SafeArrayUnaccessData(psa);

            TVariant vPostData(psa);
            TVariant vFlags = TNoParam();
            TVariant vTargetFrameName = TNoParam();
            TVariant vURL = sURL;
            TVariant vContentType =
> AnsiString("Content-Type:application/x-www-form-urlencoded\r\n");

            CppWebBrowser->Navigate2(&vURL, &vFlags, &vTargetFrameName,
&vPostData, &vContentType);
        }
    }


Gambit
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads