HttpWebRequest/Response (500) Internal Server Error RRS feed

  • Question

  • User1536465747 posted

    The target server is writen in Cold Fusion and i have no access to there.
    In addition i get only this error msg which is not very helpful:

    The remote Server returned an error: (500) Internal Server Error

    What can i do in order to come with a more friendly exception message?

    Am i overlooking something obvious in my code?

                Dim encoding As ASCIIEncoding = New ASCIIEncoding()
    Dim buffer() As Byte = encoding.GetBytes(postData)

    ' Get the URL string...
    Dim UriString As String = "http://sitename.com/blahblah ...."

    ' Prepare web request...
    Dim myRequest As HttpWebRequest = CType(WebRequest.Create(UriString), HttpWebRequest)

    ' Set the content type to a FORM
    myRequest.ContentType = "Content-Dis-data; name=somename; charset=ISO-8859-1"

    ' We use POST (method)
    myRequest.Method = "POST"

    ' Get length of content
    myRequest.ContentLength = buffer.Length

    ' Get request stream
    Dim newStream As Stream = myRequest.GetRequestStream()
    ' Send the data.
    newStream.Write(buffer, 0, buffer.Length)
    ' Close stream
    Dim myResponse As HttpWebResponse

    ' Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
    myResponse = CType(myRequest.GetResponse(), HttpWebResponse)

    ' Display the contents of the page to the console.
    Dim streamResponse As Stream = myResponse.GetResponseStream()

    ' Get stream object
    Dim streamRead As StreamReader = New StreamReader(streamResponse)

    Dim readBuffer(255) As Char

    ' Read from buffer
    Dim count As Integer = streamRead.Read(readBuffer, 0, 256)

    Do While (count > 0)
    ' get string
    Dim resultData As String = New String(readBuffer, 0, count)
    ' Read from buffer
    count = streamRead.Read(readBuffer, 0, 256)
    ' get the result
    result &= resultData

    ' Release the response object resources.

    ' Close response

    Thursday, July 30, 2009 9:06 AM

All replies

  • User-821857111 posted

    Before writing resultData to the page, check to see if the content includes the string "The remote Server returned an error: (500) Internal Server Error".  If it does, change resultData to a more friendly message.  You might just want to look at the html of the response that the ColdFusion server is returning.  That's ideally what you need to check for in your test.

    Friday, July 31, 2009 2:31 AM