Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I am trying to download a report off of our company website using VbNet. I have the following code:

VB
Dim hwrequest As Net.HttpWebRequest = Net.HttpWebRequest.Create("https://delph.am.mycompany.com/apps/Reports/ExportDocument11.asp?ID=826&Request=List&OpenType=Edit")
   hwrequest.CookieContainer = cookies
   hwrequest.Accept = "*/*"
   hwrequest.AllowAutoRedirect = False
   hwrequest.UserAgent = "http_requester/0.1"
   hwrequest.Timeout = 60000
   hwrequest.Method = "GET"
   Dim hwresponse As Net.HttpWebResponse = hwrequest.GetResponse()
   If hwresponse.StatusCode = Net.HttpStatusCode.OK Then
       Dim responseStream As IO.StreamReader = _
         New IO.StreamReader(hwresponse.GetResponseStream())
       responseData = responseStream.ReadToEnd()
   End If


But the Response object just returns

<head><title>Object moved</title></head>
   <body><h1>Object Moved</h1>This object may be found <a HREF="/Security/ErrorTrap.asp? 
   ErrorID=7">here</a>.</body>


and the Location header of the response returns: {X=46,Y=46} and I am not sure what that means.

Can anyone please tell me what I am doing wrong? Thanks in advance.
Posted
Comments
Kschuler 4-Feb-14 13:51pm    
It looks like you're hitting a web page, not a report file. Are you trying to kick of code to generate a report first or something? What exactly are you trying to retrieve?
jo106n 4-Feb-14 20:26pm    
I'm trying to retrieve a report. When you run the report from the website, a new window in IE opens with the above URL. I can also see in Fiddler that the site is going to that URL and using a Get operation. Hope that clarifies. Thanks.
Sergey Alexandrovich Kryukov 4-Feb-14 20:35pm    
What happens if you try to download the report using some available browser? Any difference?
—SA

1 solution

The HttpWebRequest class will not follow redirects like a browser will. You have to get the actual URL of the report file, not the one you're using. What you're retrieving is a HTML page that redirects to another page.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900