VS2008 WebResponse 500 Internal server error.

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,530
Location
Lansing, MI; USA
Programming Experience
10+
I'm trying to make a webpage that get's a url from another web page (this other webpage works fine in a browser, both IE and FF) but when I make the webrequest call the returned page is a 500 internal server error. Here's the code:
VB.NET:
Imports System.Net
Imports System.IO

Partial Public Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim HandlerURL As String = "http://portal.us.husqvarna.com/wps/sw-portal/DownloadHandler.jsp?type=<removed>&factory=<removed>&supplierid=<removed>&userid=<removed>&password=<removed>"
        ErrorLabel.Text = GetDownloadFile(HandlerURL)
    End Sub

    Private Function GetDownloadFile(ByVal Url As String) As String
        Dim ResponseURL As String = String.Empty
        Try
            Dim request As HttpWebRequest = CType(WebRequest.Create(Url), HttpWebRequest)

            ' Set some reasonable limits on resources used by this request
            request.MaximumAutomaticRedirections = 4
            request.MaximumResponseHeadersLength = 4

            ' Set credentials to use for this request.
            request.Credentials = CredentialCache.DefaultCredentials

            Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)

            ' Get the stream associated with the response.
            Dim receiveStream As Stream = response.GetResponseStream()

            ' Pipes the stream to a higher level stream reader with the required encoding format. 
            Dim readStream As New StreamReader(receiveStream, Encoding.UTF8)

            ' Get the returned page
            ResponseURL = readStream.ReadToEnd()

            response.Close()
            readStream.Close()
        Catch ex As Exception
            ResponseURL = ex.ToString.Replace(Environment.NewLine, "<br />")
        End Try
        Return ResponseURL.Trim
    End Function

End Class
Here's the error I'm getting:
VB.NET:
System.Net.WebException: The remote server returned an error: (500) Internal Server Error.
at System.Net.HttpWebRequest.GetResponse()
at SW_GetDownloadFile._Default.GetDownloadFile(String Url) in C:\Documents and Settings\vm\My Documents\Visual Studio 2008\Projects\SW_GetDownloadFile\SW_GetDownloadFile\Default.aspx.vb:line 24
The DownloadHandler.jsp page simply displays a text line being a text file download link, there's no html formatting or anything and when I paste that text into the browser it shows the text file contents just fine, I need my asp webpage to get that text file link so it can turn around and open it to parse the info. I'm not in control of the DownloadHandler.jsp page so i can't alter that, the Java team wont make any changes to it either.
 

Latest posts

Back
Top