HttpWebRequest returns 404 even though resource exits

W

wajih.boukaram

Hi
I've been using asp.net for a couple of days now and i think I've
gotten the hang of things
I do have a problem when using HttpWebRequest:

i request a page from a remote server and this works fine for several
pages that I've tried but for one of the pages I'm trying to get it
returns 404 even though the page exists for sure - to make sure it does
when i catch the exception i print out the failed url as a link and go
to it from there - and the page does exist when i visit it - it also
retrieves the exact same file but from different servers

any idea what's going wrong?
here's my script:

<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.IO" %>

<script language="VB" runat="server">

Sub Page_Load(sender as Object, e as EventArgs)
Response.Write("<html><body><table width = '100%' style = 'font-size:
10pt'><tr><td>Private1</td><td>Private2</td><td>Private3</td><td>Private4</td></tr>")
'Works fine
Response.Write("<tr valign = 'top'><td>" &
GetFreeSpaceList("http://index.private1.xxxxxxxxxxx.xxx/free.asp") &
"</td>")
'Works fine
Response.Write("<td>" &
GetFreeSpaceList("http://index.private2.xxxxxxxxxxx.xxx/free.asp") &
"</td>")
'Works fine
Response.Write("<td>" &
GetFreeSpaceList("http://index.private3.xxxxxxxxxxx.xxx/free.asp") &
"</td>")
'Fails even though the url does exist
Response.Write("<td>" &
GetFreeSpaceList("http://index.newreleases.xxxxxxxxxxx.xxx/free.asp") &
"</td>")
Response.Write("</tr></table></body></html>")
End Sub

Function GetFreeSpaceList(ByVal url as String) As String

Try
Dim request as HttpWebRequest
Dim response as HttpWebResponse
Dim responseString as String
request = WebRequest.Create(url)

request.AllowAutoRedirect = True
request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;
rv:1.8.1) Gecko/20061010 Firefox/2.0"
response = request.GetResponse()

responseString = new
StreamReader(response.GetResponseStream()).ReadToEnd()
Return responseString
catch Ex as Exception
Return "Error accessing " & url & "<br/>Details: " & Ex.Message
End Try
End Function

</script>
 
W

wajih.boukaram

i actually wrote the other script and it doesn't do anything special
no checking whatsoever
all it does is a couple of response.writes
and i added the useragent just in case - even with the useragent and
autoredirect removed it had the same problem
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top