Solved

View Actual Response Stream of a HttpWebRequest

Posted on 2006-06-22
5
454 Views
Last Modified: 2012-08-13
I am working with System.Net.HttpWebRequest objects and would like to see the actual response stream.

The catch - our servers require SSL - so intercepting does not work as we see the response, but it is encrypted.

I have tried the following:

using (StreamReader streamReader = new StreamReader(request.GetResponse()))
{
       Response.Write(streamReader.ReadToEnd());
}

The result is:
https://myserver.com/exchange/mrichmon/Calendar/testappointment.emlHTTP/1.1 200 OK

However if I have code similar to this:

using(XmlReader reader = XmlReader.Create(request.GetResponseStream()))
{
      reader.MoveToContent();
      while(reader.Read())
      {
            if(reader.NodeType == XmlNodeType.Element)
            {
                  Response.Write("&lt;" + reader.Name + "&gt;<br>");
                  Response.Write(reader.ReadElementString());
            }
      }
}

Then I get results like this:
<a:response>
https://myserver.com/exchange/mrichmon/Calendar/testappointment.eml<a:propstat>
HTTP/1.1 200 OK<a:contentclass>
<c:subject>
<d:location>
<d:dtend>
<d:busystatus>
<d:alldayevent>
<d:reminderoffset>

So I know there actually is xml content there.

So, the question is how do I view the actual response so that I can look at the xml, see the defined namespaces, see the fields returned, etc.

Also related is what is the best way to get this xml from teh stream into a variable that can be used in C# code
0
Comment
Question by:mrichmon
  • 2
5 Comments
 
LVL 5

Expert Comment

by:RoninThe
ID: 16963612
personally I prefer Read() to ReadToEnd(), nothing to do with your question here though. The problem seems to do with GetResponse() and GetResponseStream().
try this-

string respString = "";
using( StreamReader readStream = new StreamReader( request.GetResponseStream(), System.Text.Encoding.GetEncoding("utf-8"))
{
      Char[] read = new Char[256];
      int count = readStream.Read( read, 0, 256 );
      while (count > 0)
      {
            // Dump the 256 characters on a string.
            String str = new String(read, 0, count);
            respString += str;
            count = readStream.Read(read, 0, 256);
      }
}
Console.Write( respString);
if( respString != "")
{
      XmlDocument doc = new XmlDocument();
      try
      {
            doc.LoadXml( respString);
      }
      catch( XmlException e)
      {
      }
}
0
 
LVL 35

Author Comment

by:mrichmon
ID: 16970152
No that does not work.

Instead the output is the exact same as
using (StreamReader streamReader = new StreamReader(request.GetResponse()))
{
       Response.Write(streamReader.ReadToEnd());
}

which is https://myserver.com/exchange/mrichmon/Calendar/testappointment.emlHTTP/1.1 200 OK
0
 
LVL 35

Author Comment

by:mrichmon
ID: 16970186
Okay I figured it out.

Very simple solution - I am suprised no one mentioned it.

The problem was that since the output was going through a Response.Write - it was in the source, but only the above text was being displayed to the screen.

Simple huh :o)
0
 
LVL 1

Accepted Solution

by:
GhostMod earned 0 total points
ID: 17021930
Closed, 500 points refunded.
GhostMod
Community Support Moderator
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

822 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question