Request.TotalBytes always 0

Discussion in 'ASP .Net' started by kaczmar2@gmail.com, Nov 2, 2006.

  1. Guest

    Hello,

    I have an aspx page which is posting xml content to another asp.net
    page, but the request.length is always 0. I think there should be
    something there. below is the code for the requesting page and
    consuming page. Does anyone have any insight? Thanks.

    //CLIENT PAGE
    string xml = "<foo />";
    string uri = string.Concat("http://localhost/consume-req.aspx);

    byte[] bytes = Encoding.UTF8.GetBytes(xml);
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);

    // integrated security
    request.Credentials = CredentialCache.DefaultCredentials;

    request.Method = "POST";
    request.ContentLength = bytes.Length;
    request.ContentType = "text/xml";
    using (Stream requestStream = request.GetRequestStream())
    {
    requestStream.Write(bytes, 0, bytes.Length);
    }


    using (HttpWebResponse response =
    (HttpWebResponse)request.GetResponse())
    {
    if (response.StatusCode != HttpStatusCode.OK)
    {
    string message = POST failed.";

    }
    else
    {
    // do something with the response
    Stream stream = response.GetResponseStream();

    // convert the response data into a string
    StreamReader sr = new StreamReader(stream);
    string results = sr.ReadToEnd();
    sr.Close();

    // end the request
    stream.Close();
    }
    }


    //****************************************
    //CONSUME_REQ.ASPX
    protected void Page_Load(object sender, EventArgs e)
    {
    try
    {
    //Process Request here
    Stream stream = Request.InputStream;
    long b = Request.InputStream.Length;
    StreamReader sr = new StreamReader(stream);
    string results = sr.ReadToEnd();

    // Send the response
    Response.Clear();
    Response.ContentType = "text/xml";
    Response.CacheControl = "No-cache";
    Response.Expires = -1;
    //oResponse.Save(new StreamWriter(Response.OutputStream));
    }
    catch (Exception ex)
    {...}
    , Nov 2, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian Birtle
    Replies:
    2
    Views:
    2,017
    John Saunders
    Oct 16, 2003
  2. Gawel
    Replies:
    1
    Views:
    396
    Alvin Bruney
    Dec 31, 2003
  3. al
    Replies:
    7
    Views:
    4,084
    George
    Jun 17, 2004
  4. Deryck
    Replies:
    4
    Views:
    517
    derek giroulle
    Jun 22, 2004
  5. Replies:
    0
    Views:
    341
Loading...

Share This Page