• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Odd NSData initWithContentsOfURL: issue
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Odd NSData initWithContentsOfURL: issue


  • Subject: Re: Odd NSData initWithContentsOfURL: issue
  • From: John Stiles <email@hidden>
  • Date: Tue, 15 Mar 2005 12:01:09 -0800


On Mar 15, 2005, at 11:46 AM, John C. Randolph wrote:


On Mar 13, 2005, at 10:01 PM, Nicko van Someren wrote:

On 14 Mar 2005, at 3:27, Michael J. Sherman wrote:
I'm trying to grab XML files from various URLs and save the XML file to disk as a text file.
...
NSData *theXMLFile = [[NSData alloc] initWithContentsOfURL:xmlURL];
...
It works for most URLs I try. But there are some that result in binary garbage data in the blaa.xml file! I'm wondering if anyone has any clue where I can look to start figuring this out.

I ran into the same problem the other day but with the initWithContentsOfURL: message in NSXMLParser instead of NSData. Another site that fails is the C|Net RSS feed at: http://news.com.com/2547-1_3-0-5.xml At the time I didn't have enough time to fully test things and then I went off on holiday but seeing your mail made me come back and look at this again.


It seems that there is a real bug in the initWithContentsOfURL: code for NSData and NSString and by extension every class that uses them. A quick check of the headers sent with the request shows that they include:
Accept-Encoding: gzip, deflate;q=1.0, identity;q=0.5, *;q=0
The problem is that when the server does send back gziped data it's not getting unpacked. I just tried your code to download from the site you mentioned and from CNet and the resulting files unpack just fine on the command line using gunzip.


I will file a bug report with Apple. Given that 10.3.9 is in seed already I guess it won't get fixed before Tiger :-(

That would be a feature request, rather than a bug report. -initWithContentsOfURL: is supposed to give you whatever's at that URL, without any modifications.

I think most users would argue that the compression of the data is an artifact of the transport mechanism, and does not represent the actual data at that URL. And you should not be explicitly advertising gzip support to the server on the client's behalf if you aren't going to take responsibility for the actual gzip decompression.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Follow-Ups:
    • Re: Odd NSData initWithContentsOfURL: issue
      • From: Nicko van Someren <email@hidden>
References: 
 >Odd NSData initWithContentsOfURL: issue (From: "Michael J. Sherman" <email@hidden>)
 >Re: Odd NSData initWithContentsOfURL: issue (From: Nicko van Someren <email@hidden>)
 >Re: Odd NSData initWithContentsOfURL: issue (From: "John C. Randolph" <email@hidden>)

  • Prev by Date: Re: Odd NSData initWithContentsOfURL: issue
  • Next by Date: Re: Optimising an app for battery power use?
  • Previous by thread: Re: Odd NSData initWithContentsOfURL: issue
  • Next by thread: Re: Odd NSData initWithContentsOfURL: issue
  • Index(es):
    • Date
    • Thread