How to get from NSMutableData to NSString / URL loading issue
How to get from NSMutableData to NSString / URL loading issue
- Subject: How to get from NSMutableData to NSString / URL loading issue
- From: Mike Zornek <email@hidden>
- Date: Tue, 22 Feb 2005 22:46:03 -0500
I'm trying to familiarize myself with the Foundation URL Loading APIs and
have run into an issue. I did find some relevant posts in the archive but
nothing that cleared it up for me. I hope someone here can help.
So I want to build a simple app that has a field where the user types in the
URL of a webpage, hits a button and the source for that webpage is shown in
an NSTextView. I'm using the sample code that is part of this documentation:
http://developer.apple.com/documentation/Cocoa/Conceptual/URLLoadingSystem/T
asks/UsingNSURLConnection.html
NOTE: I'm using the Foundation URL Loading APIs (over say the NSSTring
initWIthContentsOfURL) as I suspect it's more scalable to handle hundreds of
urls (as I need to do). If I'm wrong here let me know.
So the example code is working pretty good I think. I'm in
connectionDidFinishLoading: and the log is showing good feedback and the
comment tells me to do something with the data.
Taking for granted I know this document is an html document, I'm having a
hard time taking the data and turning it into a NSString for which I can
update the NSTextView, run NSScanner over it and so forth. The problem is I
don't know how it's encoded and thus can't run NSString's
initWithData:encoding: method.
I saw in the archive someone talk of a method textEncodingName as part of
NSURLResponse but my understanding is that many servers won't send this
correctly and many times the person admin-ing the server is not the same one
who wrote the html document.
Another post in the archive suggests
NSString *htmlString = [WebCoreEncodings decodeData: htmlData];
I haven't gotten this to work yet. I think I'd need to download and build
WebCore for inclusion in my app to do so. Maybe it's in the system though
and I'm just not including it right. Building web core for this one function
seems extravagant as well. Got to be a simpler way I'm missing.
Anyways at the end of the day I have this NSMutableData object that I'm
confident is a webpage, and I'd like to turn it into an NSString. How do I
do this?
Thanks for your help.
~ Mike
-----
Mike Zornek
Web Designer, Media Developer, Programmer and Geek
Personal site: <http://MikeZornek.com>
_______________________________________________
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