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. Web Development
  3. ASP.NET
  4. Processing webpage post (automated)

Processing webpage post (automated)

Scheduled Pinned Locked Moved ASP.NET
csharphelp
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.
  • D Offline
    D Offline
    David Hovey
    wrote on last edited by
    #1

    Hi All! I am trying to process several requests to a website, performing posts of data and processing page results. I'm finding it seems very inefficient, and actually it seems to take longer to process the request than compared to typing in manually. Looking at the code below it appears there isn't a way to simplify or move initialization of objects to another method, rather than performing it each request is made (the requests are being made to the same website). Here is my code below. Thanks for all your help!

    private string ProcessFormPOST(string strURL, string strFormData)
    {
    try
    {
    //string strViewstate = GetInitialViewState(strURL);
    //strViewstate = System.Web.HttpUtility.UrlEncode(strViewstate);
    //strFormData += "&__VIEWSTATE=" + strViewstate;

                byte\[\] buffer = Encoding.UTF8.GetBytes(strFormData);
                string proxy = null;
    
                System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(strURL);
    
                req.Method = "POST";
                req.ContentType = "application/x-www-form-urlencoded";
                req.ContentLength = buffer.Length;
                req.Proxy = new System.Net.WebProxy(proxy, true); // ignore for local addresses
                req.CookieContainer = new System.Net.CookieContainer(); // enable cookies 
    
                System.IO.Stream reqst = req.GetRequestStream(); // add form data to request stream
                reqst.Write(buffer, 0, buffer.Length);
                //reqst.Flush();
                reqst.Close();
    
                System.Net.HttpWebResponse res = (System.Net.HttpWebResponse)req.GetResponse(); // send request, get response 
    
                System.IO.Stream resst = res.GetResponseStream(); // display HTTP response
                System.IO.StreamReader sr = new System.IO.StreamReader(resst);
    
                return sr.ReadToEnd();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    
    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