PC Review


Reply
Thread Tools Rate Thread

Automating dialog with web server from VB.NET

 
 
Mark Gross
Guest
Posts: n/a
 
      7th Apr 2004
I am attempting to programatically drive a Lotus Notes web application
from a VB.NET database application (who wants to rekey information in
one database into someone else's web page for entry to theirs?). I am
using the System.Net.WebClient to communicate with the LotusNotes
server. It is not clear if I should be instantiating a new object for
each communication, or persisting the initial one.

based on the input values in the web page,

<INPUT NAME="Name" VALUE="" ...
<INPUT NAME="Password" VALUE="" ...

I have established the following code:

Dim myNameValueCollection As New
System.Collections.Specialized.NameValueCollection

myNameValueCollection.Add("Name", txtMyUserName.Text)
myNameValueCollection.Add("Password",
txtMyUserPassword.Text)

Dim uriString as String = "/names.nsf?Login"
Dim myWebClient As New System.Net.WebClient

' Upload the NameValueCollection.
Dim responseArray As Byte() =
myWebClient.UploadValues(uriString, "POST", myNameValueCollection)


The application web page contains

<FORM METHOD=post ACTION="/names.nsf?Login"
NAME="_DominoForm">

When I run this, the response I get is a return of the login web page
(ie: login failed), so I assume I'm missing something.

Any suggestions?

thanks,
Mark Gross (E-Mail Removed)


PS: This application used to be run using 3270 terminal emulation screen
scraping in VB6. Now that the mainframe folks are moving to web based
applications, I have to migrate with them because they still won't allow
flat file submissions... some things haven't changed all that much.

 
Reply With Quote
 
 
 
 
Peter Huang
Guest
Posts: n/a
 
      8th Apr 2004
Hi Mark,

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you wants to post some data to a
names.nsf page.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

Since I have no Lotus Notes web application at hand, I test on an aspx page.
Here is my code on client.
Imports System.Net
Imports System.Collections.Specialized
Imports System.Text
Module Module1
Sub Main()
'Dim o As New TestCls.TestABC
'Console.WriteLine(o.Hello)
Console.Write(ControlChars.Cr + "Please enter the URL to post data
to : ")
Dim uriString As String =
"http://localhost/WebApplication6/WebForm1.aspx"
' Create a new WebClient instance.
Dim myWebClient As New WebClient
' Create a new NameValueCollection instance to hold some custom
parameters to be posted to the URL.
Dim myNameValueCollection As New NameValueCollection
Console.WriteLine("Please enter the following parameters to be
posted to the Url")
Console.Write("Name:")
Dim name As String = "TestUser"
Console.Write("Age:")
Dim age As String = ""
Console.Write("Address:")
Dim address As String = ""
' Add necessary parameter/value pairs to the name/value container.
myNameValueCollection.Add("Name", name)
myNameValueCollection.Add("Address", address)
myNameValueCollection.Add("Age", age)
Console.WriteLine(ControlChars.Cr + "Uploading to {0} ...",
uriString)
' Upload the NameValueCollection.
Dim responseArray As Byte() = myWebClient.UploadValues(uriString,
"POST", myNameValueCollection)
' Decode and display the response.
Console.WriteLine(ControlChars.Cr + "Response received was :" +
ControlChars.Cr + "{0}", Encoding.ASCII.GetString(responseArray))
End Sub
End Module

[aspx codebehind page]
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Request.Form("Name") = "TestUser" Then
Response.Write("OK")
End If
End Sub

You may try my code first with an aspx page first to isolate the problem.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
Mark Gross
Guest
Posts: n/a
 
      8th Apr 2004
Peter,

My application is a Windows form, using VB.NET. The target web application
that I wish to control is a Lotus Notes application, served from a Domino
server.


I have used the example provided below, and it does not succeed for me. Part
of the problem was learning how to handle the firewall proxy server.

The folks at Dart.Com (PowerTCP) have a web address which posts back whatever
parameters you send it, and it appears I am sending everything correctly.

I am uncertain however about a couple of things. I download the initial dialog
web
page which contains the following:

<FORM METHOD=post ACTION="/names.nsf?Login" NAME="_DominoForm">

I a using the ACTION value to post back to. Do I need to do anything with the
NAME value?

<INPUT TYPE=hidden NAME="%%ModDate" VALUE="0000000000000000">

In parsing this out, is "%%" supposed to be replaced by something, or returned
literally?

<INPUT NAME="RedirectTo" VALUE="/defaultweb.nsf/mainframeset.htm"
type=hidden></FORM>

If this is a redirect, is there anything special that needs to be done in
retrieving the results?

Thanks for your help,
mark


Peter Huang wrote:

> Hi Mark,
>
> First of all, I would like to confirm my understanding of your issue.
> From your description, I understand that you wants to post some data to a
> names.nsf page.
> Have I fully understood you? If there is anything I misunderstood, please
> feel free to let me know.
>
> Since I have no Lotus Notes web application at hand, I test on an aspx page.
> Here is my code on client.
> Imports System.Net
> Imports System.Collections.Specialized
> Imports System.Text
> Module Module1
> Sub Main()
> 'Dim o As New TestCls.TestABC
> 'Console.WriteLine(o.Hello)
> Console.Write(ControlChars.Cr + "Please enter the URL to post data
> to : ")
> Dim uriString As String =
> "http://localhost/WebApplication6/WebForm1.aspx"
> ' Create a new WebClient instance.
> Dim myWebClient As New WebClient
> ' Create a new NameValueCollection instance to hold some custom
> parameters to be posted to the URL.
> Dim myNameValueCollection As New NameValueCollection
> Console.WriteLine("Please enter the following parameters to be
> posted to the Url")
> Console.Write("Name:")
> Dim name As String = "TestUser"
> Console.Write("Age:")
> Dim age As String = ""
> Console.Write("Address:")
> Dim address As String = ""
> ' Add necessary parameter/value pairs to the name/value container.
> myNameValueCollection.Add("Name", name)
> myNameValueCollection.Add("Address", address)
> myNameValueCollection.Add("Age", age)
> Console.WriteLine(ControlChars.Cr + "Uploading to {0} ...",
> uriString)
> ' Upload the NameValueCollection.
> Dim responseArray As Byte() = myWebClient.UploadValues(uriString,
> "POST", myNameValueCollection)
> ' Decode and display the response.
> Console.WriteLine(ControlChars.Cr + "Response received was :" +
> ControlChars.Cr + "{0}", Encoding.ASCII.GetString(responseArray))
> End Sub
> End Module
>
> [aspx codebehind page]
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> 'Put user code to initialize the page here
> If Request.Form("Name") = "TestUser" Then
> Response.Write("OK")
> End If
> End Sub
>
> You may try my code first with an aspx page first to isolate the problem.
>
> Best regards,
>
> Peter Huang
> Microsoft Online Partner Support
>
> Get Secure! - www.microsoft.com/security
> This posting is provided "AS IS" with no warranties, and confers no rights.


 
Reply With Quote
 
Peter Huang
Guest
Posts: n/a
 
      9th Apr 2004
Hi Mark,

I t hink you may try to post the hidden value(%%ModDate and RedirectTo) to
the webpage in addition to Name and Password to see if the problem persists.
That is to say you may try to post four namevalues at least to the server.

You may have a try and let me know the result.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
Peter Huang
Guest
Posts: n/a
 
      13th Apr 2004
Hi Mark,

Have your tried my suggestion that try to post the hidden values to the
server side togother with the name and password?
I write the post just to want to know if the problem persists.
If you still have any concern on this issue, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
Mark Gross
Guest
Posts: n/a
 
      13th Apr 2004
Peter,

Apologies for taking a while to get back to you; I work two jobs and my wife is
undergoing chemotherapy for a very rare form of leukemia, and I've not been on
a single thread very successfully for a while...

Turns out my problem was I was posting to the address of the original source
page instead of the address in the HTML <FORM ACTION="/names.nsf?Login">

-when I send it there it successfully returns the next page, which
unfortunately is a frame.

Here is a question to follow this: How does one handle frames? The returned
page is very brief, consisting of two frames referencing two different URLs. I
would assume that there must be a way to:

retrieve main URL frame code
do until
retrieve subframe URL page code
done

all within the context of the validated parent frame? If you can help with
this, I'd be delighted!

Best regards,
Mark


Peter Huang wrote:

> Hi Mark,
>
> Have your tried my suggestion that try to post the hidden values to the
> server side togother with the name and password?
> I write the post just to want to know if the problem persists.
> If you still have any concern on this issue, please feel free to post here.
>
> Best regards,
>
> Peter Huang
> Microsoft Online Partner Support
>
> Get Secure! - www.microsoft.com/security
> This posting is provided "AS IS" with no warranties, and confers no rights.


 
Reply With Quote
 
Peter Huang
Guest
Posts: n/a
 
      14th Apr 2004
Hi Mark,

I am sorry to hear that.
Hope your wife will recover soon.

As for the question that retrieve the frame src, because the security
concern, we can not use the mshtml library to access the frame's property
directly.
As a workaround, we have to access the WebBrowser object model of frame
windows in an HTML page inside the control by using the IOleContainer
interface.

e.g. the html file we got from the post operation is as below.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
<html>
<head>
<title>Nested Hierarchy Frameset</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</head>
<frameset cols="150,*">
<frame name="left" src="http://www.google.com" scrolling="no" noresize>
<frameset rows="20%,*">
<frame name="rtop" src="http://www.microsoft.com">
<frame name="rbottom" src="http://www.yahoo.com">
</frameset>
<noframes>
<p id="p1">
This HTML frameset displays multiple Web pages. To view this frameset,
use a Web browser that supports HTML 4.0 and later.
</p>
</noframes>
</frameset>
</html>


Here is the VB.NET code to get the Frame URL.
We may need to add an WebBrowser control onto the form to achieve out goal,
but we can make the control invisible.

1. We need to declare some interface.

Imports System.Runtime.InteropServices
<ComVisible(True), Guid("0000011B-0000-0000-C000-000000000046"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
Interface IOleContainer
Sub ParseDisplayName(<[In](), MarshalAs(UnmanagedType.Interface)> ByVal
pbc As [Object], <[In](), MarshalAs(UnmanagedType.BStr)> ByVal
pszDisplayName As [String], <Out(), MarshalAs(UnmanagedType.LPArray)> ByVal
pchEaten() As Integer, <Out(), MarshalAs(UnmanagedType.LPArray)> ByVal
ppmkOut() As [Object])
Function EnumObjects(<[In](), MarshalAs(UnmanagedType.U4)> ByVal
grfFlags As Integer, <Out()> ByRef ppenum As IEnumUnknown) As Integer
Sub LockContainer(<[In](), MarshalAs(UnmanagedType.I4)> ByVal fLock As
Integer)
End Interface 'IOleContainer
Public Enum tagOLECONTF
EMBEDDINGS = 1
LINKS = 2
OTHERS = 4
ONLYUSER = 8
ONLYIFRUNNING = 16
End Enum
<ComImport(), InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
Guid("00000100-0000-0000-C000-000000000046")> _
Public Interface IEnumUnknown
<PreserveSig()> _
Function [Next](ByVal celt As Integer,
<MarshalAs(UnmanagedType.IUnknown)> ByRef rgelt As [Object], ByRef
pceltFetched As Integer) As Integer
<PreserveSig()> _
Function Skip(ByVal celt As Integer) As Integer
<PreserveSig()> _
Function Reset() As Integer
<PreserveSig()> _
Function Clone(ByRef ppenum As IEnumUnknown) As Integer
End Interface

2. We use the WebBrowser control to load the html file we get from the
post operation and save to harddisk( we note it as test.html)

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.AxWebBrowser1.Visible = False
Me.AxWebBrowser1.Navigate("c:\test.html")
End Sub

Private Sub AxWebBrowser1_DownloadComplete(ByVal sender As Object,
ByVal e As System.EventArgs) Handles AxWebBrowser1.DownloadComplete
MsgBox("Download complele")
End Sub

3. After the the document has been downloaded, we can run the code below to
get the urls.

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim pContainer As IOleContainer '
Dim o As IEnumUnknown
Dim pEnumerator As IEnumUnknown
Dim pUnk As Object
Dim pBrowser As SHDocVw.IWebBrowser2
pContainer = CType(Me.AxWebBrowser1.Document, IOleContainer)
' Get an enumerator for the frames
If pContainer.EnumObjects(tagOLECONTF.EMBEDDINGS, pEnumerator) = 0
Then
pContainer = Nothing
Dim pceltFetched As Integer = 0
' Enumerate and refresh all the frames
Do While pEnumerator.Next(1, pUnk, pceltFetched) = 0
Try
If IsNothing(pUnk) Then
Exit Do
End If
' Get the IWebBrowser2 interface
pBrowser = pUnk
Debug.WriteLine("Frame: " & pBrowser.LocationURL)
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try
pceltFetched = 0
Loop
pEnumerator = Nothing
End If
End Sub


4. Now we have the urls of the three frames, we can use the Webclient use
the download and save the content.
Here is the link about how to downloads data from a resource with the
specified URI to a local file.

WebClient.DownloadFile Method
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemnetwebclientclassdownloadfiletopic.asp

You may try my suggestion and let me know the result.


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
Mark Gross
Guest
Posts: n/a
 
      14th Apr 2004
Peter,

Thank you very much. This will keep me busy for a while. I appreciate the
guidance.

My wife had a rough night last night with a bad reaction to the chemotherapy (ICE -
ifosomide/carboplatin/etopocide) which has to be administered over 3 days in the
hospital. Although the leukemia is terminal and swift, she is actually responding
to treatment and gaining strength. We are grateful for each day.

thank you again,
mark

Peter Huang wrote:

> Hi Mark,
>
> I am sorry to hear that.
> Hope your wife will recover soon.
>
> As for the question that retrieve the frame src, because the security
> concern, we can not use the mshtml library to access the frame's property
> directly.
> As a workaround, we have to access the WebBrowser object model of frame
> windows in an HTML page inside the control by using the IOleContainer
> interface.
>
> e.g. the html file we got from the post operation is as below.
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
> <html>
> <head>
> <title>Nested Hierarchy Frameset</title>
> <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
> <meta content="http://schemas.microsoft.com/intellisense/ie5"
> name="vs_targetSchema">
> </head>
> <frameset cols="150,*">
> <frame name="left" src="http://www.google.com" scrolling="no" noresize>
> <frameset rows="20%,*">
> <frame name="rtop" src="http://www.microsoft.com">
> <frame name="rbottom" src="http://www.yahoo.com">
> </frameset>
> <noframes>
> <p id="p1">
> This HTML frameset displays multiple Web pages. To view this frameset,
> use a Web browser that supports HTML 4.0 and later.
> </p>
> </noframes>
> </frameset>
> </html>
>
> Here is the VB.NET code to get the Frame URL.
> We may need to add an WebBrowser control onto the form to achieve out goal,
> but we can make the control invisible.
>
> 1. We need to declare some interface.
>
> Imports System.Runtime.InteropServices
> <ComVisible(True), Guid("0000011B-0000-0000-C000-000000000046"),
> InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
> Interface IOleContainer
> Sub ParseDisplayName(<[In](), MarshalAs(UnmanagedType.Interface)> ByVal
> pbc As [Object], <[In](), MarshalAs(UnmanagedType.BStr)> ByVal
> pszDisplayName As [String], <Out(), MarshalAs(UnmanagedType.LPArray)> ByVal
> pchEaten() As Integer, <Out(), MarshalAs(UnmanagedType.LPArray)> ByVal
> ppmkOut() As [Object])
> Function EnumObjects(<[In](), MarshalAs(UnmanagedType.U4)> ByVal
> grfFlags As Integer, <Out()> ByRef ppenum As IEnumUnknown) As Integer
> Sub LockContainer(<[In](), MarshalAs(UnmanagedType.I4)> ByVal fLock As
> Integer)
> End Interface 'IOleContainer
> Public Enum tagOLECONTF
> EMBEDDINGS = 1
> LINKS = 2
> OTHERS = 4
> ONLYUSER = 8
> ONLYIFRUNNING = 16
> End Enum
> <ComImport(), InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
> Guid("00000100-0000-0000-C000-000000000046")> _
> Public Interface IEnumUnknown
> <PreserveSig()> _
> Function [Next](ByVal celt As Integer,
> <MarshalAs(UnmanagedType.IUnknown)> ByRef rgelt As [Object], ByRef
> pceltFetched As Integer) As Integer
> <PreserveSig()> _
> Function Skip(ByVal celt As Integer) As Integer
> <PreserveSig()> _
> Function Reset() As Integer
> <PreserveSig()> _
> Function Clone(ByRef ppenum As IEnumUnknown) As Integer
> End Interface
>
> 2. We use the WebBrowser control to load the html file we get from the
> post operation and save to harddisk( we note it as test.html)
>
> Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> Me.AxWebBrowser1.Visible = False
> Me.AxWebBrowser1.Navigate("c:\test.html")
> End Sub
>
> Private Sub AxWebBrowser1_DownloadComplete(ByVal sender As Object,
> ByVal e As System.EventArgs) Handles AxWebBrowser1.DownloadComplete
> MsgBox("Download complele")
> End Sub
>
> 3. After the the document has been downloaded, we can run the code below to
> get the urls.
>
> Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button2.Click
> Dim pContainer As IOleContainer '
> Dim o As IEnumUnknown
> Dim pEnumerator As IEnumUnknown
> Dim pUnk As Object
> Dim pBrowser As SHDocVw.IWebBrowser2
> pContainer = CType(Me.AxWebBrowser1.Document, IOleContainer)
> ' Get an enumerator for the frames
> If pContainer.EnumObjects(tagOLECONTF.EMBEDDINGS, pEnumerator) = 0
> Then
> pContainer = Nothing
> Dim pceltFetched As Integer = 0
> ' Enumerate and refresh all the frames
> Do While pEnumerator.Next(1, pUnk, pceltFetched) = 0
> Try
> If IsNothing(pUnk) Then
> Exit Do
> End If
> ' Get the IWebBrowser2 interface
> pBrowser = pUnk
> Debug.WriteLine("Frame: " & pBrowser.LocationURL)
> Catch ex As Exception
> Debug.WriteLine(ex.Message)
> End Try
> pceltFetched = 0
> Loop
> pEnumerator = Nothing
> End If
> End Sub
>
> 4. Now we have the urls of the three frames, we can use the Webclient use
> the download and save the content.
> Here is the link about how to downloads data from a resource with the
> specified URI to a local file.
>
> WebClient.DownloadFile Method
> http://msdn.microsoft.com/library/de...us/cpref/html/
> frlrfsystemnetwebclientclassdownloadfiletopic.asp
>
> You may try my suggestion and let me know the result.
>
> Best regards,
>
> Peter Huang
> Microsoft Online Partner Support
>
> Get Secure! - www.microsoft.com/security
> This posting is provided "AS IS" with no warranties, and confers no rights.


 
Reply With Quote
 
Mark Gross
Guest
Posts: n/a
 
      14th Apr 2004
Me.AxWebBrowser1.Visible = False
Me.AxWebBrowser1.Navigate("c:\test.html")

Peter,

In simulating this, I also must authenticate to a proxy server. Can I set the
globalProxySelection.Select as when using the System.Net.WebClient, or how do I do
authenticate to a proxy server with AxWebBrowser?

This is a bit obscure.
Many thanks,
mark

 
Reply With Quote
 
Peter Huang
Guest
Posts: n/a
 
      15th Apr 2004
Hi Mark,

Thanks for keeping me posted.
I understand how difficult these times are for you both, and I sincerely
hope that your wife continues to respond well to her treatment .

First I agree with that we can use the GlobalProxySelection when using
WebClient. WebClient class use WebRequest class to access the internet.
Therefore you can use GlobalProxySelection class to select a global proxy.
Then the proxy will also be used by WebClient. More information about the
proxy, please check the reference of Proxy property of HttpWebRequest class.

HttpWebRequest.Proxy Property
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfSystemNetHttpWebRequestClassProxyTopic.asp

As for the Webbrowser control, its behavior is similar with the internet
explorer. When we access a website via an authentication proxy, it will
popup a dialog to input the credential. My suggestion is to save the html
file with frame to the local disk and then load it into the webbrowser from
local so that we do not need to handle the authentication in the WebBrowser.
If you feel the approach is somewhat tedious, I think you may try to parse
the html file returned back manually when you post the username password to
the login website. So that we do not need to use the WebBrowser control.


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automating Opening Of "Help and Support Center" Dialog? (PeteCresswell) Windows XP General 1 4th Sep 2007 04:52 PM
Automating key strokes to a dialog box Scott G Microsoft Excel Programming 2 6th Nov 2006 07:18 PM
Automating a dialog box via VB sendKeys and SetTimer Bob Stark Microsoft Powerpoint 0 27th Jun 2004 11:03 AM
Re: File Open dialog box when automating import Roger Carlson Microsoft Access External Data 0 10th May 2004 06:47 PM
RE: Automating Excel on a Server Peter Huang [MSFT] Microsoft Excel Programming 0 26th Aug 2003 12:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:36 PM.