mrichmon
asked on
View Actual Response Stream of a HttpWebRequest
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.GetRe sponse()))
{
Response.Write(streamReade r.ReadToEn d());
}
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.G etResponse Stream()))
{
reader.MoveToContent();
while(reader.Read())
{
if(reader.NodeType == XmlNodeType.Element)
{
Response.Write("<" + reader.Name + "><br>");
Response.Write(reader.Read ElementStr ing());
}
}
}
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
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.GetRe
{
Response.Write(streamReade
}
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.G
{
reader.MoveToContent();
while(reader.Read())
{
if(reader.NodeType == XmlNodeType.Element)
{
Response.Write("<" + reader.Name + "><br>");
Response.Write(reader.Read
}
}
}
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
ASKER
No that does not work.
Instead the output is the exact same as
using (StreamReader streamReader = new StreamReader(request.GetRe sponse()))
{
Response.Write(streamReade r.ReadToEn d());
}
which is https://myserver.com/exchange/mrichmon/Calendar/testappointment.emlHTTP/1.1 200 OK
Instead the output is the exact same as
using (StreamReader streamReader = new StreamReader(request.GetRe
{
Response.Write(streamReade
}
which is https://myserver.com/exchange/mrichmon/Calendar/testappointment.emlHTTP/1.1 200 OK
ASKER
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)
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)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
try this-
string respString = "";
using( StreamReader readStream = new StreamReader( request.GetResponseStream(
{
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)
{
}
}