473,394 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

HttpWebRequest returns 404 even though resource exits

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
2 2254
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Dan Battagin | last post by:
Is there a known bug with the interaction between the HttpWebRequest and the ThreadPool? I current spawn several HttpWebRequest's using BeginGetResponse, and they work for a while, using worker...
18
by: Ed Davis | last post by:
The following is a code fragment from a simple parser. The return is buried inside the switch statement (the actual switch has several more cases). I can't come up with a good alternative I...
6
by: omyek | last post by:
I'm trying to mimic the browsing of a webpage using an HttpWebRequest. I've had a lot of luck with it so far, including logging into pages, posting form data, and even collecting and using cookies....
2
by: Maris Janis Vasilevskis | last post by:
Hi, Is it possible to force HttpWebRequest to do exactly (not approximately) the same as MSXML2.ServerXMLHTTP does? More details. I port JScript to JScript.NET I have a server (ASP invoking...
6
by: Oliver | last post by:
I have a very wired problem requesting one specific url from within my application. I have struggeled with this for 5 hours now, and searched google withour any luck, so i hope that someone are...
4
by: Shannon Hardin | last post by:
I'm trying to build a routine that will take a specified file from the user's local hard drive, and copy it to a remote server via WebDAV. I've tried using both HttpWebRequest and FileWebRequest,...
1
by: Will | last post by:
I have a hardware device that I need to read from. To connect to it you do a http://<name>/data and it return a few string of raw data(non- HTML format and no HTTP header). I just need to put that...
7
by: Marc Bartsch | last post by:
Hi, I have a background worker in my C# app that makes a synchronous HttpWebRequest.GetResponse() call. The idea is to POST a file to a server on the internet. When I call HttpWebRequest.Abort()...
2
by: =?Utf-8?B?TGVuc3Rlcg==?= | last post by:
A C# (.NET 2) application which uses the System.Net.HttpWebRequest object to request a resource over HTTPS is failing following the installation of a new proxy server on our internal network with...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.