Solved

View Actual Response Stream of a HttpWebRequest

Posted on 2006-06-22
5
456 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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!
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

733 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