We are successfully getting many of the reports from the iTunes autoingest endpoint: https://reportingitc.apple.com/autoingestion.tft
However some of the reports, rather than returning the data directly in the body return a ZIP file and whenever we try to read the response we get:
The magic number in GZip header is not correct. Make sure you are passing in a GZip stream.
The response headers look something like the following, indicating the zip file:
{
Content-Encoding:
Content-Disposition: attachment;filename=O_S_W_XXXXXXXX_20120805.zip
filename: O_S_W_XXXXXXXX_20120805.zip
Transfer-Encoding: chunked
Content-Type: application/a-gzip
Date: Wed, 29 Aug 2012 08:54:35 GMT
Set-Cookie: JSESSIONID=XXXXXXXXXXXXXXXX; Path=/
Server: Apache-Coyote/1.1
}
But I do not really see how to access this attachment and I think the error might be something to do with the fact that I am trying to ready both the attachment and other parts of the response in one operation whereas only part of the response is actually zipped.
The code looks something like this:
HttpWebRequest w = (HttpWebRequest)WebRequest.Create(url);
w.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
w.ContentLength = byteArray.Length;
using (Stream dataStream = w.GetRequestStream())
{
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
using (WebResponse resp = w.GetResponse())
{
using (System.IO.Compression.GZipStream s = new System.IO.Compression.GZipStream(resp.GetResponseStream(), System.IO.Compression.CompressionMode.Decompress))
{
// Just trying to read one byte causes the error.
s.ReadByte();
}
}
Any ideas greatly appreciated.