Solved

View Actual Response Stream of a HttpWebRequest

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
bulid json format 3 46
New to SOAP and need some direction 10 46
What is Thread.Sleep? 5 46
Vb.net dynamic formulas in runtime 11 62
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 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

16 Experts available now in Live!

Get 1:1 Help Now