posting session values via httpwebrequest RRS feed

  • Question

  • User-269322731 posted

    I am using the following code to post session values to another page, but it's not redirecting to the page where the data should be posting to:

    Dim poststring As String = Server.UrlEncode(String.Format("field1={0}&field2={1}", "this is a string", "this is another string"))

    Dim httpRequest As HttpWebRequest = CType(WebRequest.Create("http://localhost/posting_data.aspx"), HttpWebRequest)

    httpRequest.Method = "POST"

    httpRequest.ContentType = "application/x-www-form-urlencoded"

    Dim objUTF8Encoding As UTF8Encoding = New UTF8Encoding

    Dim arrRequest As Byte()

    arrRequest = objUTF8Encoding.GetBytes(poststring)

    httpRequest.ContentLength = arrRequest.Length

    Dim requestStream As Stream = httpRequest.GetRequestStream

    requestStream.Write(arrRequest, 0, arrRequest.Length)


    So for example, the above code is in "posting_page.aspx", when it is run it should post the data to "posting_data.aspx" therefore redirecting the user to that page and displaying the posted data etc.

    Am I missing something? Any help is much appreciated.


    Monday, December 5, 2005 4:56 AM

All replies

  • User-1803886315 posted


    this what you wrote is for me a little bit deep in http protocol problematic, so I would do it in this way:

    in posting_page.aspx:

    session("posted_data") = poststring


    and then in posting_data.aspx

    Sub Page_load(Sender as Object, e as EventArgs)

    'do something with posted data


    End Sub


    Monday, December 5, 2005 9:12 AM
  • User-269322731 posted


    The data needs to be posted as if it was a form post so that in posting_data.aspx I can retrieve the values using Request.Form("fieldname") etc. I'm simulating a form post. The values from the session need to be posted as form values to the next page.


    Monday, December 5, 2005 12:05 PM