locked
HTTP Response is returning internal server Error 500 RRS feed

  • Question

  • I have a simple aspx page. I am calling a web service inside the page to load data. I am using HTTPWebRequest to make a request to a URL. But it throws error 500(internal server error) but when I visit the URLAddress with browser it works fine.

     

    Here is my sample ASPX page.

     <form name="GetTestInformationForm" method="post" action="DnrTestInformation.aspx" id="GetTestInformationForm">

    <div>
    <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTY5NjA0OTU1MmRkCJirz74QltzVpJQy+p4e3+Pu1rE=" />
    </div>

        <h1>GVIP Test Verification</h1>
           <!-- <br />-->
            <table id="RequestTable" border="0" style="border-style:Outset;width:600px;">
        <tr id="TableRow1">
            <td id="TableCell1" align="center" colspan="2" style="border-style:Inset;">Request</td>
        </tr><tr>
            <td style="width:20%;">VIN:</td><td><input name="VinTextBox" type="text" id="VinTextBox" style="width:80%;" /></td>
        </tr><tr>
            <td id="TableCell19" style="width:30%;"></td><td colspan="2" style="font-style:italic;">VINs may not contain alphabetical characters o, i or q.</td>
        </tr><tr>
            <td style="width:30%;">Plate:</td><td><input name="PlateTextBox" type="text" id="PlateTextBox" /></td>
        </tr><tr id="TableRow2">
            <td id="TableCell2" align="center" colspan="2"><input type="submit" name="GetTestInformationButton" value="Get Test Information" id="GetTestInformationButton" /></td>
        </tr>
    </table>
     
        <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWBAKE8N3sCQK3hpruBQKJzYyQBwK03OSfBBc3gNTIESPX2MpkHfwf1OBfVYmL" />
    </div></form>

     

    Here is my VB.NET code for HTTP Web request.

     

           Try

                  req = DirectCast(Net.HttpWebRequest.Create(strCompleteURL), Net.HttpWebRequest)
                    viewState = GetViewState(output)
                    strSentInformation = "__VIEWSTATE=" + viewState
                    strSentInformation = strSentInformation + "&VinTextBox=" + strVIN + "&PlateTextBox="
                    strSentInformation = strSentInformation + "&GetTestInformationButton=" + "Get Test Information"

      
                    Dim requestBuffer As Byte() = System.Text.Encoding.ASCII.GetBytes(strSentInformation)
                    req = DirectCast(Net.HttpWebRequest.Create(strCompleteURL), Net.HttpWebRequest)
                    myCookieContainer = New System.Net.CookieContainer
                    req.Method = "Post"
                    req.ContentType = "application/x-www-form-urlencoded" 'Use when you have use Post
                    req.CookieContainer = myCookieContainer
                    req.AllowAutoRedirect = True
                    req.KeepAlive = True
                    req.ContentLength = requestBuffer.Length
                    Dim WriteStream As IO.Stream = req.GetRequestStream()
                    WriteStream.Write(requestBuffer, 0, requestBuffer.Length)
                    WriteStream.Close()
                   rsp = DirectCast(req.GetResponse, Net.HttpWebResponse)
                    reader = New StreamReader(rsp.GetResponseStream(), System.Text.Encoding.ASCII, True, 10)
                    output = reader.ReadToEnd
                    status = rsp.StatusCode.ToString()
                Catch ex As Exception
                    status = "Failure"

                End Try

     


    • Moved by Kee Poppy Monday, October 24, 2011 4:54 AM (From:Visual Basic General)
    Friday, October 21, 2011 7:53 PM

Answers