GetResponseStream returns Junk characters

  • Thread starter Thread starter SKG
  • Start date Start date
S

SKG

Iam trying to read an xml file from a website and i get junk characters. But
when i open the same file in browser
everything is fine.
here is the snippet of the code

WebRequest objRequest =
WebRequest.Create("http://www.xvdabc.com/order.xml");
WebResponse objResponse = objRequest.GetResponse();
StreamReader SR = new StreamReader(objResponse.GetResponseStream());
string strContent = oSR.ReadToEnd();


strContent has junk characters
TIA
 
SKG,

What is the encoding of the stream that is being returned? You should
specify the encoding to the StreamReader so that the bytes returned are
encoded correctly.

Hope this helps.
 
Iam using following encoding.

Encoding encoding = System.Text.Encoding.GetEncoding("utf-8");

TIA

Nicholas Paldino said:
SKG,

What is the encoding of the stream that is being returned? You should
specify the encoding to the StreamReader so that the bytes returned are
encoded correctly.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

SKG said:
Iam trying to read an xml file from a website and i get junk characters. But
when i open the same file in browser
everything is fine.
here is the snippet of the code

WebRequest objRequest =
WebRequest.Create("http://www.xvdabc.com/order.xml");
WebResponse objResponse = objRequest.GetResponse();
StreamReader SR = new StreamReader(objResponse.GetResponseStream());
string strContent = oSR.ReadToEnd();


strContent has junk characters
TIA
 
after GetResponse I found the response
object has followingproperties
ContentEncoding "x-gzip"
ContentType "text/xml" string


Nicholas Paldino said:
SKG,

What is the encoding of the stream that is being returned? You should
specify the encoding to the StreamReader so that the bytes returned are
encoded correctly.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

SKG said:
Iam trying to read an xml file from a website and i get junk characters. But
when i open the same file in browser
everything is fine.
here is the snippet of the code

WebRequest objRequest =
WebRequest.Create("http://www.xvdabc.com/order.xml");
WebResponse objResponse = objRequest.GetResponse();
StreamReader SR = new StreamReader(objResponse.GetResponseStream());
string strContent = oSR.ReadToEnd();


strContent has junk characters
TIA
 
SKG,

I don't believe that the HttpWebResponse class understands how to handle
compressed content. Because of this, you will have to run the stream
through an algorithm that will decompress the stream accoding to the x-gzip
protocol.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

SKG said:
after GetResponse I found the response
object has followingproperties
ContentEncoding "x-gzip"
ContentType "text/xml" string


message news:%[email protected]...
SKG,

What is the encoding of the stream that is being returned? You should
specify the encoding to the StreamReader so that the bytes returned are
encoded correctly.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

SKG said:
Iam trying to read an xml file from a website and i get junk
characters.
But
when i open the same file in browser
everything is fine.
here is the snippet of the code

WebRequest objRequest =
WebRequest.Create("http://www.xvdabc.com/order.xml");
WebResponse objResponse = objRequest.GetResponse();
StreamReader SR = new StreamReader(objResponse.GetResponseStream());
string strContent = oSR.ReadToEnd();


strContent has junk characters
TIA
 
Nicholas,
iam able to see the same file in the browser without any problem.
Does the browser has this decrypt algorithm build in. If so do i have to use
MSHTML components
to get the file?
Thanks!!!

Nicholas Paldino said:
SKG,

I don't believe that the HttpWebResponse class understands how to handle
compressed content. Because of this, you will have to run the stream
through an algorithm that will decompress the stream accoding to the x-gzip
protocol.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

SKG said:
after GetResponse I found the response
object has followingproperties
ContentEncoding "x-gzip"
ContentType "text/xml" string


message news:%[email protected]...
SKG,

What is the encoding of the stream that is being returned? You should
specify the encoding to the StreamReader so that the bytes returned are
encoded correctly.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Iam trying to read an xml file from a website and i get junk characters.
But
when i open the same file in browser
everything is fine.
here is the snippet of the code

WebRequest objRequest =
WebRequest.Create("http://www.xvdabc.com/order.xml");
WebResponse objResponse = objRequest.GetResponse();
StreamReader SR = new StreamReader(objResponse.GetResponseStream());
string strContent = oSR.ReadToEnd();


strContent has junk characters
TIA
 
SKG,

The browser does know how to interpret this. If you want to do it in
..NET, you can use the free Sharp Zip Library, located at (watch for line
wrap):

http://www.icsharpcode.net/OpenSource/SharpZipLib/Default.aspx


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

SKG said:
Nicholas,
iam able to see the same file in the browser without any problem.
Does the browser has this decrypt algorithm build in. If so do i have to use
MSHTML components
to get the file?
Thanks!!!

message news:%[email protected]...
SKG,

I don't believe that the HttpWebResponse class understands how to handle
compressed content. Because of this, you will have to run the stream
through an algorithm that will decompress the stream accoding to the x-gzip
protocol.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

SKG said:
after GetResponse I found the response
object has followingproperties
ContentEncoding "x-gzip"
ContentType "text/xml" string


"Nicholas Paldino [.NET/C# MVP]" <[email protected]>
wrote
in
message SKG,

What is the encoding of the stream that is being returned? You should
specify the encoding to the StreamReader so that the bytes returned are
encoded correctly.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Iam trying to read an xml file from a website and i get junk characters.
But
when i open the same file in browser
everything is fine.
here is the snippet of the code

WebRequest objRequest =
WebRequest.Create("http://www.xvdabc.com/order.xml");
WebResponse objResponse = objRequest.GetResponse();
StreamReader SR = new StreamReader(objResponse.GetResponseStream());
string strContent = oSR.ReadToEnd();


strContent has junk characters
TIA
 
Nicholas,

You are the MAN!!!!. Thanks it works!!!!

Nicholas Paldino said:
SKG,

The browser does know how to interpret this. If you want to do it in
.NET, you can use the free Sharp Zip Library, located at (watch for line
wrap):

http://www.icsharpcode.net/OpenSource/SharpZipLib/Default.aspx


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

SKG said:
Nicholas,
iam able to see the same file in the browser without any problem.
Does the browser has this decrypt algorithm build in. If so do i have to use
MSHTML components
to get the file?
Thanks!!!

message news:%[email protected]...
SKG,

I don't believe that the HttpWebResponse class understands how to handle
compressed content. Because of this, you will have to run the stream
through an algorithm that will decompress the stream accoding to the x-gzip
protocol.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

after GetResponse I found the response
object has followingproperties
ContentEncoding "x-gzip"
ContentType "text/xml" string


in
message SKG,

What is the encoding of the stream that is being returned? You
should
specify the encoding to the StreamReader so that the bytes
returned
are
encoded correctly.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Iam trying to read an xml file from a website and i get junk
characters.
But
when i open the same file in browser
everything is fine.
here is the snippet of the code

WebRequest objRequest =
WebRequest.Create("http://www.xvdabc.com/order.xml");
WebResponse objResponse = objRequest.GetResponse();
StreamReader SR = new StreamReader(objResponse.GetResponseStream());
string strContent = oSR.ReadToEnd();


strContent has junk characters
TIA
 
Back
Top