Re: stringWithContentsOfURL:encoding:error weirdness
Re: stringWithContentsOfURL:encoding:error weirdness
- Subject: Re: stringWithContentsOfURL:encoding:error weirdness
- From: "Doug Knowles" <email@hidden>
- Date: Thu, 12 Apr 2007 10:53:26 -0400
A followup with a couple of observations that surprised me. I don't
need any help, but maybe it'll help somebody else, and if anybody has
any insights into the underlying behavior, a little education is
always a good thing.
I followed Aaron Tuller's advice and replaced my usage of [NSString
stringWithContentsofURL...] with a NSURLConnection (actually,
NSURLDownload), and a whole bunch of RSS feeds I couldn't process are
now working. The oddities:
- The CNN feed I cited sends gzip'd content, but there's no indication
of that in the header, and NSURLDownload's
download:shouldDecodeSourceDataOfMIMEType:encodingType never gets
called to ask if it should be decoded, but it is anyway.
- Another site was redirecting my stringWithContentsOfURL request to
an HTML error page, but NSURLDownload receives the expected (and
desired) content. I assume that this is because it uses a secret
handshake that the NSString method does not.
- NSURLDownload was much easier to use than I expected from a quick
read of the documentation, with the added benefit of being
asynchronous.
Doug K;
On 4/8/07, Doug Knowles <email@hidden> wrote:
I have been using, quite successfully, NSString's
stringWithContentsOfURL:encoding:error to read RSS feeds from various
sources. All of sudden, I'm getting errors when trying to process
CNN's feeds (which I used to read successfully): the method returns a
null result and an encoding error:
Error: NSError "File could not be opened using text encoding Unicode
(UTF-8)." Domain=NSCocoaErrorDomain Code=261
UserInfo={NSStringEncoding = 4; NSURL =
http://rss.cnn.com/rss/money_latest.rss; }
I can download the feed using curl from the command line, and it looks
OK; the HTTP header says the content is UTF-8, the XML header says its
UTF-8, and BBEdit doesn't have any trouble opening the curl-downloaded
content.
I've tried specifying other encodings, and at best I get garbage that
can't be parsed as XML.
Any ideas? My next idea is to open and process the URL connection
myself, but I'd rather keep the simple implementation and fry other
fish first.
TIA,
Doug Knowles
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden