Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
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.
Posted
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:
  • *Experts*
Posted
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.
Posted
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?
  • *Experts*
Posted
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.
Posted
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.
  • *Experts*
Posted
Ah, OK. Here's a quick example I whipped up. It should do the trick.
    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.

  • Leaders
Posted
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?

  • *Experts*
Posted
Here's an alternative way using WebClient:
    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

Posted
Ah, OK. Here's a quick example I whipped up. It should do the trick.
    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.

Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...