Webrequest populate UserAgent and Headers

icm63 0 Reputation points
2024-05-31T01:20:28.4933333+00:00

asp net version 2.0

asp.net forms with vb.net

       Dim strData As String = String.Empty
            Dim wr As HttpWebRequest = Nothing
            Dim wrRes As HttpWebResponse = Nothing                  

  wr = DirectCast(WebRequest.Create(URi), HttpWebRequest)
                    wr.Timeout = TimeOut 'Milliseconds default is 3 minutes 180,000
                    wr.Credentials = System.Net.CredentialCache.DefaultCredentials
                    wr.Method = WebRequestMethods.Http.Get
                    wr.KeepAlive = True
                    wr.Headers.Add(HttpRequestHeader.Cookie, CookieHeader)
                    wrRes = DirectCast(wr.GetResponse(), HttpWebResponse)
                    Using strReader As StreamReader = New StreamReader(wrRes.GetResponseStream())
                        strData = strReader.ReadToEnd
                        strReader.Close()
                    End Using

I want to add

wr.UserAgent = ??
wr.Header = ??

Or is it wr.UserAgent.add ??

To show to URL request is coming via browser address bar and not a api call..

Question

  1. How do I populate wr.UserAgent to allow 'All user agents" like /
  2. How do I populate wr.Header with my browser header information

thx

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,572 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,396 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,642 questions
{count} votes