G
Guest
Hi,
This is driving me crazy. I have a solution that works great on one site,
but doesn't on another site. Same exact code on two different windows
environments. Here is the code:
Private Sub DoStuff()
Dim sURL As String
Dim XMLnews As XmlDocument = New XmlDocument
Dim XMLroot As System.Xml.XmlElement
Dim XMLHeadline As System.Xml.XmlNode
Dim XMLnode As System.Xml.XmlNode
Dim sFeed As String
Try
sURL = "http://www.microsoft.com/"
Dim myHttpWebRequest As HttpWebRequest =
CType(WebRequest.Create(sURL), HttpWebRequest)
myHttpWebRequest.Proxy = System.Net.WebProxy.GetDefaultProxy
Dim myHttpWebResponse As HttpWebResponse =
CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
Dim receiveStream As Stream =
myHttpWebResponse.GetResponseStream()
Dim encode As System.Text.Encoding =
System.Text.Encoding.GetEncoding("utf-8")
Dim readStream As New StreamReader(receiveStream, encode)
skinerror.Text = readStream.ReadToEnd.ToString
Catch ex As Exception
skinerror.Text = ex.Message.ToString & "<br>" &
ex.StackTrace.ToString
End Try
End Sub
On the good site it returns the web page (in this case Microsoft.com's home
page). On the bad site (hosted by godaddy.com) it returns:
The remote server returned an error: (401) Unauthorized.
at System.Net.HttpWebRequest.CheckFinalStatus() at
System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at
System.Net.HttpWebRequest.GetResponse() at webapp._Default.DoStuff()
I am not using credentials of any kind -- it doesn't matter what website I
point to either.
I'm at a loss -- thanks in advance.
This is driving me crazy. I have a solution that works great on one site,
but doesn't on another site. Same exact code on two different windows
environments. Here is the code:
Private Sub DoStuff()
Dim sURL As String
Dim XMLnews As XmlDocument = New XmlDocument
Dim XMLroot As System.Xml.XmlElement
Dim XMLHeadline As System.Xml.XmlNode
Dim XMLnode As System.Xml.XmlNode
Dim sFeed As String
Try
sURL = "http://www.microsoft.com/"
Dim myHttpWebRequest As HttpWebRequest =
CType(WebRequest.Create(sURL), HttpWebRequest)
myHttpWebRequest.Proxy = System.Net.WebProxy.GetDefaultProxy
Dim myHttpWebResponse As HttpWebResponse =
CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
Dim receiveStream As Stream =
myHttpWebResponse.GetResponseStream()
Dim encode As System.Text.Encoding =
System.Text.Encoding.GetEncoding("utf-8")
Dim readStream As New StreamReader(receiveStream, encode)
skinerror.Text = readStream.ReadToEnd.ToString
Catch ex As Exception
skinerror.Text = ex.Message.ToString & "<br>" &
ex.StackTrace.ToString
End Try
End Sub
On the good site it returns the web page (in this case Microsoft.com's home
page). On the bad site (hosted by godaddy.com) it returns:
The remote server returned an error: (401) Unauthorized.
at System.Net.HttpWebRequest.CheckFinalStatus() at
System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at
System.Net.HttpWebRequest.GetResponse() at webapp._Default.DoStuff()
I am not using credentials of any kind -- it doesn't matter what website I
point to either.
I'm at a loss -- thanks in advance.