?
Solved

How to invoke IE through Com component in vc++

Posted on 2007-10-17
12
Medium Priority
?
987 Views
Last Modified: 2013-11-20
I invoked IE using com component "CComQIPtr<IWebBrowser2>". In that I used "Navigate2" method to invoke the IE with the appropriate URL. Here when i formed the URL i sent the user id and password for authentication for that web page. This user id and pwd and both visible in the browser which is raising security concerns. How can I send them similar to post method or make them invisible though web page but still get authenticated in the server?
0
Comment
Question by:arunperi_ee
  • 5
  • 4
  • 3
12 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 20094084
0
 
LVL 86

Expert Comment

by:jkr
ID: 20094114
BTW, see also the example at http://www.microsoft.com/downloads/details.aspx?familyid=5255950D-ED9A-419D-BDA3-55FBE6E21F57&displaylang=en ("Sample: Using IAuthenticate to Bind to Secured Web Page")
0
 

Author Comment

by:arunperi_ee
ID: 20101082
Hi,

I am not using IAuthenticate can you please clarify where exactly I can modify the code or how i can go about:
I have used CComQIPtr<IWebBrowser2> m_pWebBrowser1;
m_pWebBrowser1.CoCreateInstance(CLSID_InternetExplorer);
hr = m_pWebBrowser1->Navigate2(.....)

Where can I used the interface that you have quoted.

Can you please elaborate with an example if possible which could help me know exactly the solution.

Thanks.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 86

Expert Comment

by:jkr
ID: 20101656
Plese check the example linked above, that would be a little too much code to post here.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 20106482
   Navigate2 Method
    http://msdn2.microsoft.com/en-us/library/aa752094.aspx

I assume that the URL looks something like:

     http://www.someWebSite.com/login?id=theUser&pswd=thePassword

That is a HTTP GET transaction.  If so, you can change to using the POST version of that call:  Populate the 4th parameter with a string that contains all of the stuff after the
    ?
in the URL.  That will hide it from view.

If the website requires the other kind of security (where the browser pops up a gray box requesting the user and password) then you can send that data in the 5th parameter.  You need to create a header line in the format:

Authorization: Basic %s\r\n

where %s is a string in the format
   user:password
and it has been base64-encoded.  If this is the need, let me know and I'll explain further.
 
-- Dan
0
 

Author Comment

by:arunperi_ee
ID: 20112575
Hi Dan,

Yes when we are sending the user id and password in the URL it can be easily interpreted. Though I am able to login to the site.

The best would be to use Post method to open the URL. But there should be no dialog opening up it should happen without that and once the link is clicked it should happen smoothly with no further authentication.

Can you please explain how it can be encoded or invoked using POST method.

---Arun.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 20113003
If a GET URL works, then a POST URL should also work -- without poping up a dialog box.

Just do as I recommended:  Put the stuff that normally comes after the
   ?
into the 4th parameter (the PostData) and remove all of it (including the ?) from the first parameter (the URL).

-- Dan
0
 

Author Comment

by:arunperi_ee
ID: 20125194
Hi Dan,

I have done that but still it's not working. I invoked using:

            hr = m_pWebBrowser2->Navigate2(&vaURL,
                        COleVariant((long) 0, VT_I4),
                        COleVariant((LPCTSTR)NULL, VT_BSTR),
                        &vaLoginCredent,
                        COleVariant((LPCTSTR)NULL, VT_BSTR)
                        );

where vaURL contains: www.<<URL>>
and vaLoginCredent contains: <<Crerdentials = <<...>> UserID= <<UID>> Password=<<PWD>>

Please let me know where I am going wrong.

Thanks,
Arun.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 20126218
First, the POST data should look the same as when it is in the URL, including the ampersand (&) signs.  For instance,

  Credentials=blahBlah&UserID=blechBlech&Password=fooFoo

Next, the first parameter should be a Variant.  I can't tell what it is in your code.  But since you are using
        &vaURL,
I can tell that you are passing a pointer to something, which may be incorrect.  An example usage is here:

    How To Automate Internet Explorer to POST Form Data
    http://support.microsoft.com/kb/q167658/

I'm seeing that the fourth parmeter must be a VARIANT of type
   VT_ARRAY | VT_UI1
that is, a SafeArray of bytes, so we can't just pass a simple string.

A sequence like this will work:

      COleVariant vaUrl= (LPCSTR)"http://www.somesite.com/account/login,asp";

      char* szFormData= "userName=SomeName&userPswd=SomePassword";

      COleSafeArray vaFormdata;
      DWORD dwPostDataLen= lstrlen( szFormData );
      vaFormdata.CreateOneDim( VT_UI1, dwPostDataLen, szFormData );

      m_Browser.Navigate2( vaUrl, 0, 0, vaFormdata, 0 );

-- Dan
0
 

Author Comment

by:arunperi_ee
ID: 20126891
Thanks Dan for the effort but it still doesn't work.
I have done the way you guided me Dan, please refer below:

CString strBrowseToURL = "http://" + strURL +"/" + strFolder;
CString strLoginCredent = "Credentials="+ str +"&userid=" + strUserId +"&password=" + strPassword;
            
char *szFormData = strLoginCredent.GetBuffer(strLoginCredent.GetLength());
strLoginCredent.ReleaseBuffer();
COleSafeArray vaFormdata;
DWORD dwPostDataLen = lstrlen( szFormData );
vaFormdata.CreateOneDim( VT_UI1, dwPostDataLen, szFormData );

CoInitialize(NULL);
CComQIPtr<IWebBrowser2>      m_pWebBrowser2;
m_pWebBrowser2.CoCreateInstance(CLSID_InternetExplorer);
COleVariant vaURL((LPCTSTR)strBrowseToURL);
hr = m_pWebBrowser2->Navigate2(&vaURL,
COleVariant((long) 0, VT_I4),
COleVariant((LPCTSTR)NULL, VT_BSTR),
&vaFormdata,
COleVariant((LPCTSTR)NULL, VT_BSTR));

Guess I am missing something. I will see what's going wrong.

Thanks,
Arun.
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 1500 total points
ID: 20127380
You are using
   &vaURL
instead of
   vaURL
and you need to fix that.

What I recommend is that to get past the errors, remove the complications:  
Simply hard-code the two parts (szFormData and vaUrl) it as I did -- only use the actual URL and the actual text of the formData.   Once it's working with hard-coded literals, change back to the more complicated coding.

It's only about 6 lines of code.  Check each line carefully.
0
 

Author Comment

by:arunperi_ee
ID: 20245189
Thanks Dan. Infact I was waiting to verify the above said code with the other dev team.

Thank you once again.

---Arun.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question