I am using HttpWebRequest to connect to one of our services. When I attempt to connect to it, it appears that the browser version info is not passed. Here is my sample page: <script runat="server"> Sub Page_Load(s as Object, e as EventArgs) Dim objRequest
as HttpWebRequest Dim strRequest as String Dim arrRequest as Byte() Dim objUTF8Encoding as UTF8Encoding Dim strmRequest as Stream Dim objResponse as HttpWebResponse Dim srResponse as StreamReader objRequest = CType(WebRequest.Create("https://localhost/login.asp"),
HttpWebRequest) objRequest.Method = "POST" objRequest.ContentType = "application/x-www-form-urlencoded" strRequest = "username=jgaylord&password=password" objUTF8Encoding = New UTF8Encoding arrRequest = objUTF8Encoding.GetBytes(strRequest) objRequest.ContentLength
= arrRequest.Length strmRequest = objRequest.GetRequestStream() strmRequest.Write(arrRequest, 0, arrRequest.Length) strmRequest.Close() objResponse = objRequest.GetResponse() srResponse = New StreamReader(objResponse.GetResponseStream(), Encoding.ASCII) litResults.Text
= srResponse.ReadToEnd() srResponse.Close() End Sub </script> <form runat="server">
Header
Footer
</form> I grabbed this sample code from ASP.NET Unleashed.
Jason N. Gaylord
ASPInsider and Microsoft MVP
http://jasongaylord.com
I suspect that the problem is caused by the fact that there is really no 'browser' behind the HttpGetRequest object. If memory serves, browser detection is predicated on the presence of the User-Agent header. This is certainly true with the adaptive rendering
in ASP.NET. I don't see anything in your code placing such a header in the request. And there is no automatic transfer of the headers from incoming on your ASP.NET page to the request you're making to https://localhost/login.asp So if you were to add the appropriate
User-Agent header, then I believe the login.asp would indeed be to determine what the incoming browser was. HTH
Bruce Johnson [.NET MVP]
http://www.objectsharp.com/blogs/Bruce
Member
87 Points
683 Posts
ASPInsiders
MVP
HttpWebRequest drops Browser Version
May 28, 2004 04:41 PM|j_gaylord|LINK
<script runat="server"> Sub Page_Load(s as Object, e as EventArgs) Dim objRequest as HttpWebRequest Dim strRequest as String Dim arrRequest as Byte() Dim objUTF8Encoding as UTF8Encoding Dim strmRequest as Stream Dim objResponse as HttpWebResponse Dim srResponse as StreamReader objRequest = CType(WebRequest.Create("https://localhost/login.asp"), HttpWebRequest) objRequest.Method = "POST" objRequest.ContentType = "application/x-www-form-urlencoded" strRequest = "username=jgaylord&password=password" objUTF8Encoding = New UTF8Encoding arrRequest = objUTF8Encoding.GetBytes(strRequest) objRequest.ContentLength = arrRequest.Length strmRequest = objRequest.GetRequestStream() strmRequest.Write(arrRequest, 0, arrRequest.Length) strmRequest.Close() objResponse = objRequest.GetResponse() srResponse = New StreamReader(objResponse.GetResponseStream(), Encoding.ASCII) litResults.Text = srResponse.ReadToEnd() srResponse.Close() End Sub </script> <form runat="server">
I grabbed this sample code from ASP.NET Unleashed.Header
Footer
</form>ASPInsider and Microsoft MVP
http://jasongaylord.com
None
0 Points
206 Posts
Re: HttpWebRequest drops Browser Version
May 30, 2004 01:10 PM|BruceJohnson|LINK
http://www.objectsharp.com/blogs/Bruce
None
0 Points
2 Posts
Re: HttpWebRequest drops Browser Version
Jun 22, 2004 06:15 AM|www.jakub.dk|LINK