I've been testing using WebClient.DownloadString and sometimes I encounter an error: "The remote server returned an error: (403) Forbidden". It is based upon which url I use. For instance, this works:
But this doesn't:Code:Dim wc As New Net.WebClient Dim strResult As String = String.Empty Try strResult = wc.DownloadString("http://en.wikipedia.org/wiki/President_of_the_United_States") Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.OkOnly, "ex") End Try
The only difference is the url. The only difference I can see in the pages is that the second page is a bit larger. However, I also tried "http://en.wikipedia.org/wiki/The_Holocaust", which is larger than the Obama page (it would appear) and it worked just fine. I can load the Obama page in a WebBrowser just fine, so I have no idea why DownloadString is failing on that.Code:Dim wc As New Net.WebClient Dim strResult As String = String.Empty Try strResult = wc.DownloadString("http://en.wikipedia.org/wiki/Barack_Obama") Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.OkOnly, "ex") End Try
Any thoughts? Thanks.
Sorry about using political pages, I just during testing that the Obama pages always fails.




Reply With Quote