I'm currently writing a c# window forms application, that starts an instance of the internet explorer, navigates to a certain intranet page, fills out a form and submits that form.
Here is some of the code:
int state = 0;
SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorer();
ie.DocumentComplete += ie_DocumentComplete;
ie.Visible = false;
string url = "http://xch:8080/intro/open/index.jsp";
ASCIIEncoding Encode = new ASCIIEncoding();
byte[] post = Encode.GetBytes("check=Agd3458HD3jhf");
string postHeaders = "Content-Type: application/x-www-form-urlencoded";
state = 1;
ie.Navigate2(url, null, null, post, postHeaders);
private void ie_DocumentComplete(object pDisp, ref object URL)
{
if (state == 1)
{
//call a function that fills out the form, submits it and sets "state" to 2
}
else if (state == 2)
{
ie.Visible = true;
}
}
This is basically it. But there seem to occur some major problems with the "xch" in the url. When i use the ip-address instead everything is fine. With "xch" something gets messed up:
- The browser window already shows up on "ie.Navigate2(...)"
- The
DocumentComplete
event handler is never reached - When i try to access the
HTMLDocument
or someElements
in it, an Exception is thrown
My client insists to have the "xch" in the address bar instead of the ip-address and my first thought was, that it wouldn't matter, because the browser can reach the page either way. But obviously i was wrong :/ I also should mention, that the problem doesn't always occur when i use "xch". So far it only occurs on Windows 7 PCs with IE9 and a user that doesn't have admin rights. So, my question would be if anyone else had similar issues and what can i do to narrow the problem?