Request.TotalBytes always 0

  • Thread starter Thread starter kaczmar2
  • Start date Start date
K

kaczmar2

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)
{...}
 
Back
Top