Solved

View Actual Response Stream of a HttpWebRequest

Posted on 2006-06-22
5
450 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now