httprequest

leontager

Regular
Joined
Jun 17, 2003
Messages
89
could I use httprequest to tell the server which browser I am using (explorer or nescape). Maybe using httprequest.browser. I found some information regarding this but I can not understand it very well. I would really aprecciate if someone could provide me with a bit of code.
 
The UserAgent property of the HttpRequest object will contain the raw user-agent string.
 
I am very sorry if it sounds stupid but I am a bit new to VB. my question is how would you set it to what I need which is explorer or netscape. also how do I report back to the server as explorer or netscape browser:confused:
 
You mean you want to *set* the user-agent? I doubt that's possible; the browser is what does that when it sends the HTTP headers. It is done automatically however, so you should never need to worry about it.
 
well when I try to get hte source of a particular website it tells me that my browser is not allowed. How can I tell him that I am using either internet explorer or netscape?
 
If you are using IE or Netscape, the browsers are already telling the server that's what you are using. I suggest you use something like Telnet or CURL to download the source directly.
 
oh I am sorry..I wasn't clear enough on my question. I have written a program that is suppose to download a source from a website and find something in the html. I create a stream and attempt to download it but instead of what I would get with internet explorer or netscape I get a page which says that my browser is not allowed. How could I tell it that I am using explorer. I had one idea which I would put an invisible explorer window into my program and tell it to navigate to the website and get the source. My problem is that I am not sure how to get the source afterwards. Anotehr idea was using something like httprequest.browser but I am not sure how to set it.
 
Ah, OK. Here's a quick example I whipped up. It should do the trick.
Visual Basic:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim hr As HttpWebRequest = hr.Create("http://www.test.com/")
        Dim wr As HttpWebResponse
        Dim sr As IO.StreamReader

        hr.UserAgent = "Browser Name"

        wr = hr.GetResponse()
        sr = New IO.StreamReader(wr.GetResponseStream())
        TextBox1.Text = sr.ReadToEnd
    End Sub
HttpRequest is only for ASP.NET (which is why I assumed you were using it), so you need HttpWebRequest.
 
I create a stream and attempt to download it but instead of what I would get with internet explorer or netscape I get a page which says that my browser is not allowed.

that tends to happen if you are attempting to download / access a webpage which requires authentication ( either via cookies , or username / password )
for example, if you try to retrieve the source for a url like this...
http://some-site.net?
it comes up with " browser incompitable " because it needs authentication.

where as if the url was changed to this...
http://some-site.net?Id="Your UserName"&pwd="Your Password"
it would allow access to the webpage.

not sure if that helps, have you tried accessing the site via internet explorer / netscape etc... and looked at how the url is built up?
 
Here's an alternative way using WebClient:
Visual Basic:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim wc As New WebClient()
        Dim b As Byte()

        wc.Headers.Add("User-Agent", "My Browser")
        b = wc.DownloadData("http://www.test.com/")

        TextBox1.Text = System.Text.ASCIIEncoding.ASCII.GetString(b)
    End Sub
 
VolteFace said:
Ah, OK. Here's a quick example I whipped up. It should do the trick.
Visual Basic:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim hr As HttpWebRequest = hr.Create("http://www.test.com/")
        Dim wr As HttpWebResponse
        Dim sr As IO.StreamReader

        hr.UserAgent = "Browser Name"

        wr = hr.GetResponse()
        sr = New IO.StreamReader(wr.GetResponseStream())
        TextBox1.Text = sr.ReadToEnd
    End Sub
HttpRequest is only for ASP.NET (which is why I assumed you were using it), so you need HttpWebRequest.

heh sorry I missed your post. you must have posted when I was replying. Thank you for your advice. yes this site does require me to enter login and password however I get the same message also on hte home page. the first method VolteFace suggested works perfectly. I will also try out the other method. Thank you again.
 
hmm...are there any other parameters that I should set so that the server would know for sure that I am using internet explorer? I have set the browser name to "Microsoft Internet Explorer MSIE 6.0"

Dim hr As HttpWebRequest = hr.Create("http://ricelawn.freemethodistchurch.org/browserchek.html")

Dim wr As HttpWebResponse
Dim sr As IO.StreamReader
hr.UserAgent = "Microsoft Internet Explorer"

wr = hr.GetResponse()
sr = New IO.StreamReader(wr.GetResponseStream())
writer.Write(sr.ReadToEnd)

I am using hte code above but I get a blank page for some reason
 
Back
Top