Looking for a silent webbrowser
Hello all.
I am in a bit of a situation here, because the default webbrowser control freezes my application.
I'm trying to load the data of a website into structures/classes and update them ever 5 seconds. I am now using webbrowser controls, by delegate-creating them and using them in my threads.
The problem is, that all those webbrowsers count up and lag my application terribly. Every 5 seconds it is impossible for the user to control the program; it freezes.
Does anyone know of a thread-friendly webbrowser/control that can:
- Disable navigation to certain urls (navigation events)
- Give events on document completed
- Return an html document (not text)
- Does not lag the program when navigating
I'm looking for a "silent" webbrowser. It doesn't have to display elements, I do want to read the elements.
I tried using htmlrequests, but the problem with that is that I need to stay logged in. If I request a different page with a htmlrequest (when I logged in), the server returns an "not logged-in error". As far I know you can't redirect htmlrequests after logging in, so I'm stuck at that point. :(
Re: Looking for a silent webbrowser
Quote:
Return an html document (not text)
What do you mean by "html document"? HTML is just text...
Re: Looking for a silent webbrowser
Instead of reloading the data on your webpage, have you considered running a separate application that updates a bunch of XML files every five seconds? Check the information and replace the XML file if something has changed. Then on your page, just have your various controls check the timestamp on those XML files and do an update for the page if there's a new file. That way, you get the five second refresh you need, but the processing is happening off on its own and not clogging up the page the users are using.
Re: Looking for a silent webbrowser
Only problem with this is that there is an actual "normal" webbrowser enxt to it; and I can not be logged on 2 programs at once. (session ended)
Of course I tried to use a separate app to do all the update stuff, but it was simply not possible. :(
So I need a webbrowser to use in my update threads OR I need some sort of html-request at which I can use the credentials of my webbrowser.
(I log-in with a webbrowser, and the html request can get pages behind user-login)
Re: Looking for a silent webbrowser
why use the webbrowser control at all, why not use the webclient classes?
Re: Looking for a silent webbrowser
I'll try to explain:
First of all, the website doesn't use cookies but "sessions". This means, that if you close the application you are no longer logged in. You need to log-in every time to prevent the session error.
So, if I use a webclient or httpwebrequest, it fails because the request isn't connected to the program. It returns the session error.
The only solution I found is using a webbrowser, this control seems to store the session data and allow to redirect.
If you know some way to log-in and navigate infinite times with a webclient, tell me. :confused:
Re: Looking for a silent webbrowser
You need to check the header information in the WebResponse object returned by (WebRequest).GetResponse(). It will contain the header information.
Re: Looking for a silent webbrowser
Ah so you use the header of the response for a new request?
EDIT
Ow not good. It fails to set the new headers:
Code:
Dim H1 As Net.HttpWebRequest = HttpWebRequest.Create(LOGINURL)
Dim Resp1 As HttpWebResponse = H1.GetResponse
Dim H2 As HttpWebRequest = HttpWebRequest.Create(SecondURL)
'Setting seconday request headers
H2.Headers.Clear()
H2.Headers = Resp1.Headers 'Fails to set header; name property invalid; argument exception
'Executing secondary request
Dim Resp2 As HttpWebResponse = H2.GetResponse
Dim reader As New StreamReader(resp2.GetResponseStream())
WebBrowser1.DocumentText = reader.ReadToEnd()
Resp1.Close()
Resp2.Close()
reader.Close()
Any ideas?
Re: Looking for a silent webbrowser
The headers are a collection, and you only want the Session header, so:
Code:
Dim h As String = response.Headers("Session")
request.Headers.Add("Session", h)
or something like that.
Re: Looking for a silent webbrowser
Nah at this point I need to use all headers the response gave, and pass them on in the next request. I believe that is sort of the same way the webbrowser works with sessions.
How can I use all headers of the response in the new request?
This didn't work:
Code:
For Each h As String In Resp1.Headers
H2.Headers.Add(h, Resp1.Headers(h))
Next
(error: This header must be modified using the appropriate property. Parameter name: name)
Aw afraid this isn't going to work...
Got the headers to work, but it still returns the session error as result.
What exactly do I have to do, to simulate a webbrowser using httpwebrequests?
(as example, I navigate to an url and the site logs me in, sets cookies and returns an header. How do I do all this?)
Re: Looking for a silent webbrowser
Quote:
Nah at this point I need to use all headers the response gave, and pass them on in the next request. I believe that is sort of the same way the webbrowser works with sessions.
No, it's not. Did you even try the code I posted?
Check out the documentation, btw.
Re: Looking for a silent webbrowser
yep already read the documentation through, but it doesn't give an answer.
- I managed to set cookies using a logged-in webbrowser
- I managed to set the headers
The big question here: (I'll try to formulate it better)
How can I send a second httpwebrequest after a previous request logged me in onto the server. The second request must recognize me as "logged-in".
Re: Looking for a silent webbrowser
I just told you... you need to send the Session headers too. Possibly send other cookies as well, depending on the response. This says you can add a name/value pair to the headers collection. If you wanted to copy every header, you'd use:
Code:
For Each k As String In response.Headers.Keys
request.Headers.Add(k, response.Headers(k))
Next
It probably won't work for you, because you most likely only need to copy the Session header, but you can examine the headers in Debug mode and see what the server returns.