473,385 Members | 1,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

ICSharpCode.SharpZipLib.GZip.GZipInputStream Use with HTTP Request

I am using the .NET socket class to program a web client. When I come
upon gzip encoded conent, I am having trouble getting the decoded text.
I have found the ICSharpCode.SharpZipLib to help, but in using their
sample code, I keep encountering an error message about the first byte
not matching. Clearly it is expecting a certain byte value as the
first byte, which leads me to think that I need to split the encoded
body away from the unencoded header, and send only the encoded part to
the GZIPInputStream. While I know that division is determined by a
blank line, when I split it over that line (whether I include the
carriage return in the encoded part or not) I still get the same error.
Has anyone been able to use that library for decoding a webpage that
has a gzipped body?
thanks!

Dec 29 '05 #1
11 11226
<mw*****@gmail.com> wrote:
I am using the .NET socket class to program a web client. When I come
upon gzip encoded conent, I am having trouble getting the decoded text.
I have found the ICSharpCode.SharpZipLib to help, but in using their
sample code, I keep encountering an error message about the first byte
not matching. Clearly it is expecting a certain byte value as the
first byte, which leads me to think that I need to split the encoded
body away from the unencoded header, and send only the encoded part to
the GZIPInputStream. While I know that division is determined by a
blank line, when I split it over that line (whether I include the
carriage return in the encoded part or not) I still get the same error.
Has anyone been able to use that library for decoding a webpage that
has a gzipped body?


I suggest you split the problem into two halves. You need to check
that:

1) You can zip something up and then unzip it
2) You can transfer binary data without loss in a web request

I suspect your problem is in the second part, but you should be able to
work on that entirely separately from the first part.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 30 '05 #2
I'm not sure how your post addresses my issue - are you suggesting that
I don't need to break the web page into header/body in order to use the
gzip library and that my problem is elsewhere?

Dec 30 '05 #3
<mw*****@gmail.com> wrote:
I'm not sure how your post addresses my issue - are you suggesting that
I don't need to break the web page into header/body in order to use the
gzip library and that my problem is elsewhere?


I'm suggesting that you should try to make sure you can successfully
transmit/receive arbitrary binary data to work out whether that's the
problem or whether it's the gzipping that's the problem.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 30 '05 #4
I'm getting the data back - it's just gobbeldy gook when I try and use
Encoding.UTF8 (which is what is in the header) to turn it into a
string. Non- gzipped requests come back fine. I have narrowed the
issue to what I originally asked.
thanks!

Dec 30 '05 #5
<mw*****@gmail.com> wrote:
I'm getting the data back - it's just gobbeldy gook when I try and use
Encoding.UTF8 (which is what is in the header) to turn it into a
string. Non- gzipped requests come back fine.
Of arbitrary binary data? Sorry, it's not entirely clear what's going
on here - probably my fault. Could you give more information about the
server, exactly what's doing the gzipping etc?
I have narrowed the issue to what I originally asked.


So you're getting back exactly the same data as you sent? In that case,
you should be able to ignore the web part, and concentrate on just the
gzip part; you should be unable to unzip some data directly after
zipping it.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 30 '05 #6
I'm making an http request to a web page - not my web server. I don't
know what's being sent, but what I'm getting backed has been encoded as
gzip - I need to decode it.

Jan 3 '06 #7
mw*****@gmail.com wrote:
I'm making an http request to a web page - not my web server. I don't
know what's being sent, but what I'm getting backed has been encoded as
gzip - I need to decode it.


Okay - save the content you get back (as a binary file) and then try to
make the same request using the .NET HTTP classes (even if you won't be
able to do that in your production code). Save that as well, then
compare the two files.

I suspect that you're somehow misinterpreting the data which is coming
back from the web server.

Another line of approach: can you persuade the web server to give you
back a binary file (uncompressed) whose contents you know exactly? An
image would be a good start. Again, download it with your class and
save the contents, then compare with the correct file.

Jon

Jan 3 '06 #8
I get gobledy gook back from the socket class and the correct decoded
data in the http class. Httpwebrequest handles this already; my
question has been how to implement this with the sockets class. I
don't want to get into a discussion of why to use or not use the
sockets class, I just need help implementing this with the sockets
class.
thanks.

Jan 3 '06 #9
<mw*****@gmail.com> wrote:
I get gobledy gook back from the socket class and the correct decoded
data in the http class. Httpwebrequest handles this already; my
question has been how to implement this with the sockets class. I
don't want to get into a discussion of why to use or not use the
sockets class, I just need help implementing this with the sockets
class.


Have you tried my other suggestion? I'm sure the problem is that you're
not getting the binary data back correctly - try downloading an image
(not gzipped) and see whether you can correctly save it in your code.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 3 '06 #10
yes I can - I can also get non-gzipped pages back correctly.

Jan 4 '06 #11
<mw*****@gmail.com> wrote:
yes I can - I can also get non-gzipped pages back correctly.


So if you save the data back without gunzipping it yourself, then try
to run a "standard" gunzip tool, does that give you back the data
correctly?

Could you post the code you're using to gunzip?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 4 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Fran?ois-Xavier Testard-Vaillant | last post by:
In a Perl script I want to send several http requests WITHOUT waiting for the remote servers answer (i.e. just triggering http requests) and without having to create lots of processes... Thanks...
10
by: thomas parquier | last post by:
Hello Can someone give the snippet to send a post http request in order to send a soap request ? I have the complete http request but I don't know how to send it. TIA
2
by: Robert Oschler | last post by:
I have an IMG element that I've been using to send messages back to my server whenever certain item option choices are made by a visitor. I send each message by forming a URL with various search...
8
by: mike | last post by:
regards: What is the precise URL(or URI) in a HTTP Request @@.? Any positive suggestion is welcome. thank you May goodness be with you all
1
by: Calvin Slater | last post by:
I am always getting the following error when debuging ASP.NET application: Access is denied: 'ICSharpCode.SharpZipLib'. At this point I have to reboot IIS to get the web site going again. It...
5
by: Henrik | last post by:
Hi, I am trying to read some industrial webservers using the HTTP/CGI webequest like this: wrs = (HttpWebRequest)WebRequest.Create(HTTP/CGI-string); mwst = (HttpWebResponse wrs.GetResponse();...
4
by: Sam | last post by:
Hi all, Does someone knows if I can use this librairy (ICSharpCode.SharpZipLib.Zip) for free ? It is used to zip files (as you can probably guess). Thank you very much. Samuel
1
by: omantawy | last post by:
Hi, I have some legacy ASP web applications that use an unmanaged COM component to connect to a third party application. The third part application has moved to the managed code in the current...
5
by: rpjanaka | last post by:
Hi all, I am using AJAX to submit a data from a web page, it is properly working on the local host (when test with the local machine it is ok).also when access from another machine the pages are...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.