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. Http Post

Http Post

Scheduled Pinned Locked Moved ASP.NET
comquestion
2 Posts 2 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
    Dot Net Dev
    wrote on last edited by
    #1

    Hi, I am working with the HTTP Post method to log the user into my framework. But when I run the page it does not redirect to the Page given in URL. What I am doing wrong? Following is my code: string strResponse; string strPost; protected void Page_Load(object sender, EventArgs e) { strPost = "txtUserName=abc&txtPassword=123"; UTF8Encoding objUTFEncode = new UTF8Encoding(); byte[] arrRequest = null; Stream objStreamReq; StreamReader objStreamRes; HttpWebRequest objHttpRequest; HttpWebResponse objHttpResponse; Uri objUri = new Uri("http://www.mysite.com"); objHttpRequest = HttpWebRequest.Create(objUri) as HttpWebRequest; objHttpRequest.KeepAlive = false; objHttpRequest.Method = "POST"; objHttpRequest.ContentType = "application/x-www-form-urlencoded"; arrRequest = objUTFEncode.GetBytes(strPost); objHttpRequest.ContentLength = arrRequest.Length; objStreamReq = objHttpRequest.GetRequestStream(); objStreamReq.Write(arrRequest, 0, arrRequest.Length); objStreamReq.Close(); CookieContainer cookieContainer = new CookieContainer(); objHttpRequest.CookieContainer = cookieContainer; //Get response objHttpResponse = objHttpRequest.GetResponse() as HttpWebResponse; objStreamRes = new StreamReader(objHttpResponse.GetResponseStream(), Encoding.ASCII); strResponse = objStreamRes.ReadToEnd(); objStreamRes.Close(); } Thanks

    N 1 Reply Last reply
    0
    • D Dot Net Dev

      Hi, I am working with the HTTP Post method to log the user into my framework. But when I run the page it does not redirect to the Page given in URL. What I am doing wrong? Following is my code: string strResponse; string strPost; protected void Page_Load(object sender, EventArgs e) { strPost = "txtUserName=abc&txtPassword=123"; UTF8Encoding objUTFEncode = new UTF8Encoding(); byte[] arrRequest = null; Stream objStreamReq; StreamReader objStreamRes; HttpWebRequest objHttpRequest; HttpWebResponse objHttpResponse; Uri objUri = new Uri("http://www.mysite.com"); objHttpRequest = HttpWebRequest.Create(objUri) as HttpWebRequest; objHttpRequest.KeepAlive = false; objHttpRequest.Method = "POST"; objHttpRequest.ContentType = "application/x-www-form-urlencoded"; arrRequest = objUTFEncode.GetBytes(strPost); objHttpRequest.ContentLength = arrRequest.Length; objStreamReq = objHttpRequest.GetRequestStream(); objStreamReq.Write(arrRequest, 0, arrRequest.Length); objStreamReq.Close(); CookieContainer cookieContainer = new CookieContainer(); objHttpRequest.CookieContainer = cookieContainer; //Get response objHttpResponse = objHttpRequest.GetResponse() as HttpWebResponse; objStreamRes = new StreamReader(objHttpResponse.GetResponseStream(), Encoding.ASCII); strResponse = objStreamRes.ReadToEnd(); objStreamRes.Close(); } Thanks

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      Dot-Net-Dev wrote:

      What I am doing wrong?

      First, you are not following the guidelines for posting here. Use the pre tags to format any code you post. Of course it's not redirecting because you are not telling it to. All you are doing is writting, or attemtpting to, the content of the web request to the output stream of the same page. This is NOT the way to a redirect. Use Response.Redirect. This is also not the way to authenticate users. I suggst you read up on forms based authentication.


      I know the language. I've read a book. - _Madmatt

      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