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. CAN SOMEBODY PLEASEEEEEE...

CAN SOMEBODY PLEASEEEEEE...

Scheduled Pinned Locked Moved C#
questionphpcom
4 Posts 3 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.
  • F Offline
    F Offline
    fadee
    wrote on last edited by
    #1

    How can I request a web page using POST while passing some variables? Like I want to access http://www.localhost.com/info.aspx with POST and with variables info=0 and set=1 ? I have tried stupid HttpWebRequest BUT it is NOT WORKING :((... I posted the question few days back BUT nobody answered it... GURU PPL where ARE YOU??? me doing this.. string lcUrl = "http://localhost/test.php"; HttpWebRequest loHttp = (HttpWebRequest) WebRequest.Create(lcUrl); string lcPostData = "info=" + System.Web.HttpUtility.UrlEncode("0") + "&set=" + System.Web.HttpUtility.UrlEncode("1"); loHttp.Method="POST"; byte [] lbPostBuffer = System.Text.Encoding.GetEncoding(1252).GetBytes(lcPostData); loHttp.ContentLength = lbPostBuffer.Length; Stream loPostData = loHttp.GetRequestStream(); loPostData.Write(lbPostBuffer,0,lbPostBuffer.Length); loPostData.Flush(); loPostData.Close(); HttpWebResponse loWebResponse = (HttpWebResponse) loHttp.GetResponse(); System.Text.Encoding enc = System.Text.Encoding.GetEncoding(1252); StreamReader loResponseStream = new StreamReader(loWebResponse.GetResponseStream(),enc); string lcHtml = loResponseStream.ReadToEnd(); Console.Write(lcHtml); loWebResponse.Close(); loResponseStream.Close(); --------------------- A gasp of breath, A sudden death: The tale begun. A rustled page Passes an age: The tale is done.

    A 1 Reply Last reply
    0
    • F fadee

      How can I request a web page using POST while passing some variables? Like I want to access http://www.localhost.com/info.aspx with POST and with variables info=0 and set=1 ? I have tried stupid HttpWebRequest BUT it is NOT WORKING :((... I posted the question few days back BUT nobody answered it... GURU PPL where ARE YOU??? me doing this.. string lcUrl = "http://localhost/test.php"; HttpWebRequest loHttp = (HttpWebRequest) WebRequest.Create(lcUrl); string lcPostData = "info=" + System.Web.HttpUtility.UrlEncode("0") + "&set=" + System.Web.HttpUtility.UrlEncode("1"); loHttp.Method="POST"; byte [] lbPostBuffer = System.Text.Encoding.GetEncoding(1252).GetBytes(lcPostData); loHttp.ContentLength = lbPostBuffer.Length; Stream loPostData = loHttp.GetRequestStream(); loPostData.Write(lbPostBuffer,0,lbPostBuffer.Length); loPostData.Flush(); loPostData.Close(); HttpWebResponse loWebResponse = (HttpWebResponse) loHttp.GetResponse(); System.Text.Encoding enc = System.Text.Encoding.GetEncoding(1252); StreamReader loResponseStream = new StreamReader(loWebResponse.GetResponseStream(),enc); string lcHtml = loResponseStream.ReadToEnd(); Console.Write(lcHtml); loWebResponse.Close(); loResponseStream.Close(); --------------------- A gasp of breath, A sudden death: The tale begun. A rustled page Passes an age: The tale is done.

      A Offline
      A Offline
      Arjan Einbu
      wrote on last edited by
      #2

      Hmmm... Strange. This looks nothing like mine did... ;P Well, this worked for me:

      Encoding enc = Encoding.GetEncoding("ISO-8859-1");

      WebClient wc = new WebClient();

      wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded; charset=ISO-8859-1");

      string request = "input_name=the_value";
      byte[] requestBytes = enc.GetBytes(request);
      byte[] responseArray = wc.UploadData(uriString, "POST", requestBytes);

      string responseString = enc.GetString(responseArray);


      Have a look at my latest article about Object Prevalence with Bamboo Prevalence.

      F E 2 Replies Last reply
      0
      • A Arjan Einbu

        Hmmm... Strange. This looks nothing like mine did... ;P Well, this worked for me:

        Encoding enc = Encoding.GetEncoding("ISO-8859-1");

        WebClient wc = new WebClient();

        wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded; charset=ISO-8859-1");

        string request = "input_name=the_value";
        byte[] requestBytes = enc.GetBytes(request);
        byte[] responseArray = wc.UploadData(uriString, "POST", requestBytes);

        string responseString = enc.GetString(responseArray);


        Have a look at my latest article about Object Prevalence with Bamboo Prevalence.

        F Offline
        F Offline
        fadee
        wrote on last edited by
        #3

        ahhh... you don know what you have just done! Gave me life... YES...Thank you very much... a thousand :rose: for you; to fill your room with fregrence... mE --------------------- A gasp of breath, A sudden death: The tale begun. A rustled page Passes an age: The tale is done.

        1 Reply Last reply
        0
        • A Arjan Einbu

          Hmmm... Strange. This looks nothing like mine did... ;P Well, this worked for me:

          Encoding enc = Encoding.GetEncoding("ISO-8859-1");

          WebClient wc = new WebClient();

          wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded; charset=ISO-8859-1");

          string request = "input_name=the_value";
          byte[] requestBytes = enc.GetBytes(request);
          byte[] responseArray = wc.UploadData(uriString, "POST", requestBytes);

          string responseString = enc.GetString(responseArray);


          Have a look at my latest article about Object Prevalence with Bamboo Prevalence.

          E Offline
          E Offline
          eggie5
          wrote on last edited by
          #4

          do you know how to tell what webserver a site is running? /\ |_ E X E GG

          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