Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Setting the UserAgent for WebRequest

Setting the UserAgent for WebRequest

Scheduled Pinned Locked Moved C#
csharpagentic-aialgorithmstoolsquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Brad Wick
    wrote on last edited by
    #1

    I have tried searching and everything I find says to use "WebRequest.UserAgent" but this isnt a valid option in my solution to add. Am I doing something wrong? The script is pulling content from the webpage 100% correctly, I just want to be able to specify the user agent also.

                byte\[\] data = System.Text.Encoding.ASCII.GetBytes(FormVariables);
    
                System.IO.Stream os = null;
                WebRequest request = null;
                WebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultCredentials;
    
                request = WebRequest.Create(URL);
    
                request.ContentType = "application/x-www-form-urlencoded";
                request.Method = "POST";
                request.ContentLength = data.Length;
                request.Timeout = 420000;
    
                os = request.GetRequestStream();
                os.Write(data, 0, data.Length);
                os.Close();
    
                System.Net.WebResponse resp = null;
                resp = request.GetResponse();
    
                System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
                strResponse = sr.ReadToEnd().Trim();
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups