• 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: UTF-8 string encoding bug in stringWithContentsOfURL?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: UTF-8 string encoding bug in stringWithContentsOfURL?


  • Subject: Re: UTF-8 string encoding bug in stringWithContentsOfURL?
  • From: "Doug Knowles" <email@hidden>
  • Date: Mon, 16 Jul 2007 10:41:13 -0400

Ken,
Sorry, I didn't see your response right away: be warned that NSXMLDocument's
initWithContentsOfURL: is subject to the "...WithContentsOfURL" warning.

Doug K;

On 7/8/07, Ken Tozier <email@hidden> wrote:

Thanks Doug

I'll give NSURLDownload a try. Also looks like NSXMLDocument might be
a possibility.

Ken

On Jul 8, 2007, at 1:49 PM, Doug Knowles wrote:

> Hi, Ken,
>
>
> I've seen this, and got burned by the followup, too.
>
>
> I was getting the same errors from stringWithContentsOfURL:, and
> was advised on this list that the ...WithContentsOfURL methods will
> sometimes fail in this fashion if the server if gzip'ing the
> results before sending them back.  This was very confusing, because
> my alternate techniques for examining the URL responses (typically
> "curl" on the command line) handle the gzip'd responses invisibly.
>
>
> Following the advice I got, I changed my code to use NSURLDownload
> (which turned out to be relatively painless), and my erroneous
> UTF-8 errors went away.
>
>
> One caveat: I am doing my downloading on separate threads, and
> NSURLDownload turned up a separate problem wherein it invokes the
> downloadDidFinish: callback on the main thread (instead of the
> invoking thread, as it's supposed to) when the response is an
> error.  If you're doing all your work on the main thread, this
> won't affect you, but otherwise you might want to go straight to
> NSURLConnection to fetch your data.
>
>
> Hope this helps; let me know if I can clarify any of this.
>
>
> Doug K;
>
> On 7/8/07, Ken Tozier <email@hidden> wrote: 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:
> 40gmail.com
>
> This email sent to email@hidden
>

_______________________________________________


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

_______________________________________________

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


References: 
 >UTF-8 string encoding bug in stringWithContentsOfURL? (From: Ken Tozier <email@hidden>)
 >Re: UTF-8 string encoding bug in stringWithContentsOfURL? (From: "Doug Knowles" <email@hidden>)
 >Re: UTF-8 string encoding bug in stringWithContentsOfURL? (From: Ken Tozier <email@hidden>)

  • Prev by Date: Re: Difficult NSShadow problem
  • Next by Date: Half-height lines?
  • Previous by thread: Re: UTF-8 string encoding bug in stringWithContentsOfURL?
  • Next by thread: Releasing WebView After Caching
  • Index(es):
    • Date
    • Thread