UTF-8 string encoding bug in stringWithContentsOfURL?
UTF-8 string encoding bug in stringWithContentsOfURL?
- Subject: UTF-8 string encoding bug in stringWithContentsOfURL?
- From: Ken Tozier <email@hidden>
- Date: Sun, 8 Jul 2007 11:15:24 -0400
Hi
I'm writing up a few image search functions for popular search sites
(Google, Yahoo, MSN) and ran into a problem with NSString's
stringWithContentsOfURL at MSN. Doing a "view source" on the results
of an image search indicates that the search results are encoded as
utf-8 (charset=utf-8) but stringWithContentsOfURL reports the error:
"File could not be opened using text encoding Unicode (UTF-8)."
Both Google and Yahoo define charset like this "charset=UTF-8" could
the fact that MSN defines it as "charset=utf-8" (note the lowercase)
be confusing NSString?
Next I tried "stringWithContentsOfURL:usedEncoding:error:" leaving it
up to NSString to figure out what type of encoding to use but got the
error: "The file could not be opened using specified text encoding."
Safari seems to have no problem interpreting the search result so
there must be a way to do it. Does anyone know if there is any other
way to get the url contents into an NSString?
For the adventurous, here's a prepackaged MSN image query that works
in Safari but not with stringWithContentsOfURL
NSError *err = nil;
NSString *result = [NSString stringWithContentsOfURL: [NSURL
urlWithString: @"http://search.msn.com/images/results.aspx?q=white
+tiger"]
encoding: NSUTF8StringEncoding
error: &err];
TIA
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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