EDN Admin
Well-known member
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
<br/>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTY5NjA0OTU1MmRkCJirz74QltzVpJQy+p4e3+Pu1rE=" /><br/>
<br/>
<br/>
<h1>GVIP Test Verification</h1><br/>
<!-- <br />--><br/>
<table id="RequestTable" border="0" style="border-style:Outset;width:600px; <br/>
<tr id="TableRow1 <br/>
<td id="TableCell1" align="center" colspan="2" style="border-style:Inset; Request</td><br/>
</tr><tr><br/>
<td style="width:20%; VIN:</td><td><input name="VinTextBox" type="text" id="VinTextBox" style="width:80%;" /></td><br/>
</tr><tr><br/>
<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><br/>
</tr><tr><br/>
<td style="width:30%; Plate:</td><td><input name="PlateTextBox" type="text" id="PlateTextBox" /></td><br/>
</tr><tr id="TableRow2 <br/>
<td id="TableCell2" align="center" colspan="2 <input type="submit" name="GetTestInformationButton" value="Get Test Information" id="GetTestInformationButton" /></td><br/>
</tr><br/>
</table><br/>
<br/>
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWBAKE8N3sCQK3hpruBQKJzYyQBwK03OSfBBc3gNTIESPX2MpkHfwf1OBfVYmL" /><br/>
</form>
Here is my VB.NET code for HTTP Web request.
Try
req = DirectCast(Net.HttpWebRequest.Create(strCompleteURL), Net.HttpWebRequest)<br/>
viewState = GetViewState(output)<br/>
strSentInformation = "__VIEWSTATE=" + viewState<br/>
strSentInformation = strSentInformation + "&VinTextBox=" + strVIN + "&PlateTextBox="<br/>
strSentInformation = strSentInformation + "&GetTestInformationButton=" + "Get Test Information"<br/>
<br/>
<br/>
Dim requestBuffer As Byte() = System.Text.Encoding.ASCII.GetBytes(strSentInformation)<br/>
req = DirectCast(Net.HttpWebRequest.Create(strCompleteURL), Net.HttpWebRequest)<br/>
myCookieContainer = New System.Net.CookieContainer<br/>
req.Method = "Post"<br/>
req.ContentType = "application/x-www-form-urlencoded" Use when you have use Post<br/>
req.CookieContainer = myCookieContainer<br/>
req.AllowAutoRedirect = True<br/>
req.KeepAlive = True<br/>
req.ContentLength = requestBuffer.Length<br/>
Dim WriteStream As IO.Stream = req.GetRequestStream()<br/>
WriteStream.Write(requestBuffer, 0, requestBuffer.Length)<br/>
WriteStream.Close()<br/>
rsp = DirectCast(req.GetResponse, Net.HttpWebResponse)<br/>
reader = New StreamReader(rsp.GetResponseStream(), System.Text.Encoding.ASCII, True, 10)<br/>
output = reader.ReadToEnd<br/>
status = rsp.StatusCode.ToString()<br/>
Catch ex As Exception<br/>
status = "Failure"
End Try
<br/>
View the full article
Here is my sample ASPX page.
<form name="GetTestInformationForm" method="post" action="DnrTestInformation.aspx" id="GetTestInformationForm
<br/>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTY5NjA0OTU1MmRkCJirz74QltzVpJQy+p4e3+Pu1rE=" /><br/>
<br/>
<br/>
<h1>GVIP Test Verification</h1><br/>
<!-- <br />--><br/>
<table id="RequestTable" border="0" style="border-style:Outset;width:600px; <br/>
<tr id="TableRow1 <br/>
<td id="TableCell1" align="center" colspan="2" style="border-style:Inset; Request</td><br/>
</tr><tr><br/>
<td style="width:20%; VIN:</td><td><input name="VinTextBox" type="text" id="VinTextBox" style="width:80%;" /></td><br/>
</tr><tr><br/>
<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><br/>
</tr><tr><br/>
<td style="width:30%; Plate:</td><td><input name="PlateTextBox" type="text" id="PlateTextBox" /></td><br/>
</tr><tr id="TableRow2 <br/>
<td id="TableCell2" align="center" colspan="2 <input type="submit" name="GetTestInformationButton" value="Get Test Information" id="GetTestInformationButton" /></td><br/>
</tr><br/>
</table><br/>
<br/>
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWBAKE8N3sCQK3hpruBQKJzYyQBwK03OSfBBc3gNTIESPX2MpkHfwf1OBfVYmL" /><br/>
</form>
Here is my VB.NET code for HTTP Web request.
Try
req = DirectCast(Net.HttpWebRequest.Create(strCompleteURL), Net.HttpWebRequest)<br/>
viewState = GetViewState(output)<br/>
strSentInformation = "__VIEWSTATE=" + viewState<br/>
strSentInformation = strSentInformation + "&VinTextBox=" + strVIN + "&PlateTextBox="<br/>
strSentInformation = strSentInformation + "&GetTestInformationButton=" + "Get Test Information"<br/>
<br/>
<br/>
Dim requestBuffer As Byte() = System.Text.Encoding.ASCII.GetBytes(strSentInformation)<br/>
req = DirectCast(Net.HttpWebRequest.Create(strCompleteURL), Net.HttpWebRequest)<br/>
myCookieContainer = New System.Net.CookieContainer<br/>
req.Method = "Post"<br/>
req.ContentType = "application/x-www-form-urlencoded" Use when you have use Post<br/>
req.CookieContainer = myCookieContainer<br/>
req.AllowAutoRedirect = True<br/>
req.KeepAlive = True<br/>
req.ContentLength = requestBuffer.Length<br/>
Dim WriteStream As IO.Stream = req.GetRequestStream()<br/>
WriteStream.Write(requestBuffer, 0, requestBuffer.Length)<br/>
WriteStream.Close()<br/>
rsp = DirectCast(req.GetResponse, Net.HttpWebResponse)<br/>
reader = New StreamReader(rsp.GetResponseStream(), System.Text.Encoding.ASCII, True, 10)<br/>
output = reader.ReadToEnd<br/>
status = rsp.StatusCode.ToString()<br/>
Catch ex As Exception<br/>
status = "Failure"
End Try
<br/>
View the full article