By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,060 Members | 1,893 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,060 IT Pros & Developers. It's quick & easy.

HttpWebRequest returns 404 even though resource exits

P: n/a
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()).ReadToE nd()
Return responseString
catch Ex as Exception
Return "Error accessing " & url & "<br/>Details: " & Ex.Message
End Try
End Function

</script>

Dec 1 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

Dec 1 '06 #2

P: n/a
Can you post a "short but complete" (Jon Skeet :
http://www.yoda.arachsys.com/csharp/complete.html ) code block that enables
someone to replicate the issue?
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"wa************@gmail.com" wrote:
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

Dec 1 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.