locked
HttpWebRequest drops Browser Version RRS feed

  • Question

  • User1088344998 posted
    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:<%@ Page Language="VB" %> <%@ Import Namespace="System.Net" %> <%@ Import Namespace="System.IO" %> <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

    <asp:Literal id="litResults" runat="server"></asp:Literal>

    Footer

    </form>
    I grabbed this sample code from ASP.NET Unleashed.
    Friday, May 28, 2004 4:41 PM

All replies

  • User-886813230 posted
    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
    Sunday, May 30, 2004 1:10 PM
  • User-1891718285 posted
    Hi Could you maybe secify your answer with some code, that could be used. That would be nice, because I have the same problem :-) \jakub
    Tuesday, June 22, 2004 6:15 AM